Bansal, Vikas
2011-Jul-25 16:00 UTC
[R] Extrat rows from a dataframe based on second data frame
Dear all, I have also attached my question in txt file because of bad column spacing. I have two data frames df Chr Pos CaseA CaseC CaseG CaseT 10 135349878 0.000000 3.428571 0.000000 20.571429 10 135349880 0.000000 21.333333 0.000000 2.666667 10 135349883 21.000000 0.000000 3.000000 0.000000 10 135349912 0.000000 0.000000 21.000000 3.000000 10 135349913 0.000000 21.000000 0.000000 3.000000 mydf V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 10 135349459 a A 14 0 0 7 ,.,,,., bSa`^aa 10 135349878 a A 11 0 0 7 ,,,,,.. aaab^ab 10 135349877 g G 18 0 0 7 ,,,,,.. `a`_\\`b 10 135349912 g G 18 0 0 8 ,,,,,.., `_abXbba 10 135349881 a A 14 0 0 8 ,,,,..,. a`_aab_a I want to have a new data frame with all rows in mydf whose 2nd column matches the second column of df. so output of new data frame- newdf V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 10 135349878 a A 11 0 0 7 ,,,,,.. aaab^ab 10 135349912 g G 18 0 0 8 ,,,,,.., `_abXbba Can you please help me.I will be very thankful to you. Thanking you, Warm Regards Vikas Bansal Msc Bioinformatics Kings College London -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: problem.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110725/aa37c4c4/attachment.txt>
Dieter Menne
2011-Jul-25 18:14 UTC
[R] Extrat rows from a dataframe based on second data frame
Bansal, Vikas wrote:> > > I have two data frames > > df > > Chr Pos CaseA CaseC CaseG CaseT > 10 135349878 0.000000 3.428571 0.000000 20.571429 > 10 135349880 0.000000 21.333333 0.000000 2.666667 > 10 135349883 21.000000 0.000000 3.000000 0.000000 > 10 135349912 0.000000 0.000000 21.000000 3.000000 > 10 135349913 0.000000 21.000000 0.000000 3.000000 > > > mydf > > V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 > 10 135349459 a A 14 0 0 7 ,.,,,., bSa`^aa > 10 135349878 a A 11 0 0 7 ,,,,,.. aaab^ab > 10 135349877 g G 18 0 0 7 ,,,,,.. `a`_\\`b > 10 135349912 g G 18 0 0 8 ,,,,,.., `_abXbba > 10 135349881 a A 14 0 0 8 ,,,,..,. a`_aab_a > > I want to have a new data frame with all rows in mydf whose 2nd column > matches the second column of df. > .. > >(not tested) merge(mydf,df[,"Pos",drop=FALSE], by.x=V2,by.y="Pos") Not sure if drop=FALSE is needed. Dieter -- View this message in context: http://r.789695.n4.nabble.com/Extrat-rows-from-a-dataframe-based-on-second-data-frame-tp3693195p3693534.html Sent from the R help mailing list archive at Nabble.com.