my question is:
If i have the next df:
df<- data.frame(Respuestas=c("sí, acepto, a veces, no acepto",
"no acepto, sí, acepto, a veces, nunca",
"a veces, sí, acepto, nunca, bla bla"))
print(df)
Respuestas
1 sí, acepto, a veces, no acepto
2 no acepto, sí, acepto, a veces, nunca
3 a veces, sí, acepto, nunca, bla bla
So I needed to extract by columns all string they matched "Respuestas
" column with a dictionary, so I applied the @divibisan solution here. So far, all very good, I get my output
vec<-c("sí, acepto", "a veces", "no acepto")
t(apply(df, 1, function(x)
str_extract_all(x[['Respuestas']], vec, simplify = TRUE)))
[,1] [,2] [,3]
[1,] "sí, acepto" "a veces" "no acepto"
[2,] "sí, acepto" "a veces" "no acepto"
[3,] "sí, acepto" "a veces" ""
But, finally I want to get a data frame with the non-match values between "Respuestas" column string and the vec dictionary, something like this:
wishDF<- data.frame(noMatch1=c(NA,
"nunca",
"nunca"),
noMatch2= c(NA,NA, "bla bla"))
print(wishDF)
noMatch1 noMatch2
1 <NA> <NA>
2 nunca <NA>
3 nunca bla bla
I was trying to use str_detect
and invert_match
from stringr
library in the same way that @divibisan solution, but I dont get good result. What do you recommend me?
Thank you very much!