[R] logical vector of the indices of a string in a vector
carol white
wht_crl at yahoo.com
Sun Jan 24 19:24:51 CET 2016
Hi, it might be trivial but is there any way to get the logical vector of the indices of a string in a vector? I thought that %in% would do but it doesn't. I also want to filter the empty fields.
Here I want to extract the non-empty elements containing "Yes":x =c("Yes, fsd", "", "No","","Yes, fjsdlf", "")
x[c("Yes") %in% x & x != ""]character(0)
Above, I wanted to do the 2 following operations in 1. Here with grep, it works but %in% in above doesn't:y = x[grep("Yes", x)]
> y = y[y != ""]
> y
[1] "Yes, fsd" "Yes, fjsdlf"
Thanks
Carol
[[alternative HTML version deleted]]
More information about the R-help
mailing list