Reputation: 441
I have a data frame(A)
of size (92047x2) and a list(B)
of size (1829). I want to create a new data frame with all rows of A whose first column value is present in B.
How to use which()
? Or any other good way to approach this?
All the values are in form of character. (Eg. "Vc2345")
Upvotes: 0
Views: 1405
Reputation: 3787
You can do it like that:
dfA=data.frame(C1=sample(1:92047), C2=sample(1:92047))
listB=list(sample(1:1829))
dfAinB=dfA[which(dfA$C1 %in% unlist(listB)),]
str(dfAinB)
Upvotes: 3