I have 2 extracted data sets from a dataset called babies2009( 3 vectors count, name, gender )
One is girls2009 containing all the girls and the other boys2009.
I want to find out what similar names exist between boys and girls.
I tried this
common.names = (boys2009$name %in% girls2009$name)
When I try
babies2009[common.names, ] [1:10, ]
all I get is the girl names not the common names.
I have confirmed that both data sets indeed contain boys and girls respectively by doing taking a 10 sample…
boys2009 [1:10,]
girsl2009 [1:10,]
How else can I compare the 2 datasets and determine what values they both share.
Thanks,
common.names = (boys2009$name %in% girls2009$name)gives you a logical vector of lengthlength(boys2009$name). So when you try selecting from a much longer data.framebabies2009[common.names, ] [1:10, ], you wind up with nonsense.Solution: use that logical vector on the proper data.frame!