I am new to R, and I am having trouble using stringr on a dataset. I am trying to subset the data by variables with the word restaurant in them against those with out. I constantly get this error message.
str_detect(matrix(expandedDataFrame[1,12:21],1,
ncol(expandedDataFrame[,12:21])),"Restaurants")
Error: String must be an atomic vector
You get an error because str_detect
is expecting an atomic
type as first argument. I guess that if you use as.matrix
and not matrix
your code will work.
Indeed:
is.atomic(matrix(data.frame(c=1:10,c1=5:1)))
[1] FALSE
> is.atomic(as.matrix(data.frame(c=1:10,c1=5:1)))
[1] TRUE
So your code becomes:
str_detect(as.matrix(expandedDataFrame[1,12:21],1,
ncol(expandedDataFrame[,12:21])),"Restaurants")
But since you don't give a reproducible example, this is just a guess....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With