I'm trying to subset using a vector of characters. I'd like to pull back all rows whose corresponding X column are in this vector. My experimenting is bringing back zilch and so is my search.
list<-c("1","2","3")
sub<-subset(data,x==list,1:4)
That and syntax pretty close to it won't work.
Thanks!
As mentioned by @bunk you could use the %in%
operator:
DF <- data.frame(id=c(1,2,3),val=c(4,5,6))
val.list <- c(5,6)
subDF <- subset(DF, val %in% val.list)
subDF
id val
2 2 5
3 3 6
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.