0

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")

10 Rep
  • 2,217
  • 7
  • 19
  • 33
Kavipriya
  • 441
  • 4
  • 17
  • this looks like a subsetting problem but without a piece of code or at least an expected output is hard to help you. Please refer to this post: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – SabDeM Jun 18 '15 at 09:50
  • Read `help("%in%")`. – Roland Jun 18 '15 at 09:54

1 Answers1

3

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)
cyberj0g
  • 3,707
  • 1
  • 19
  • 34