0

I have a dataframe, and now I would like to extract some rows by a column content. For example:

name <- c("John","Lily","Cat","King")
record <- c(2,6,10,3)
dftry <- data.frame(name,record)
list <- c("John","cat")

I want to extract the row which dftry$name == "John" | "cat" (which is in the list) how can I do that? I have tried

dftry[dftry$name==list,]  #but this do not gonna work
dftry[which(dftry$name == "John"| dftry$name =="Cat"),]  #this would work but the real list is thousands long than 2.

So how can I do it easily? Thank you

Codezy
  • 662
  • 5
  • 17

0 Answers0