I do have a dataframe like this one
columna <- c(1,2,3)
columnb <- c("a b e", "c d", "a c d")
columnc <- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))
alldata <- data.frame(columna,columnb,columnc)
tokeep <- c("c", "e")
And i would like to get the same alldata
with columnb
modified to only keep in columnb
the strings found in tokeep
.
Ideally, i would like to have alldata$columnb
to be
[ "e", "c", "c" ]
I first thought i could use something like
filter(alldata, alldata$columnb %in% tokeep)
alldata[which(alldata$b %in% tokeep), ]
but i can't manage to find a solution.
Can someone guide me on this ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…