Mauluda Akhtar
2010-Nov-05 16:26 UTC
[R] How to extract particular rows and column from a table
Hello, I'm a new user of R. I've a very big table like the following structure (suppose the variable name with "aa"). From this table I want to make a new table which'll contain just two column with V2 and V6 with some particular rows( Suppose, variable name with "bb"). I'd like to mention V2 column is representing the id that correspond to the column V6 whis is represention the base position of DNA. In this bb table, just for an example I want to extract all the corresponding rows of V2 column where in V6 column there is "30049831" (in my table there is repeatation of same base position). I tried this but faild to solve. Could you please let me know how can i solve this. Thank you. Mauluda V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 ESME HEP0102102796h05.w2kF59780SCF:32 CpG Variation 6 30049831 30049831 + . -1 NA ESME HEP0102102796h05.w2kF59780SCF:114 CpG Variation 6 30049913 30049913 + . 31 NA ESME HEP0102102796h05.w2kF59780SCF:154 CpG Variation 6 30049953 30049953 + . 48 NA ESME HEP0102102796h05.w2kF59780SCF:170 CpG Variation 6 30049969 30049969 + . 30 NA ESME HEP0102102796h05.w2kF59780SCF:172 CpG Variation 6 30049971 30049971 + . 38 NA ESME HEP0102102796h05.w2kF59780SCF:245 CpG Variation 6 30050044 30050044 + . 14 NA ESME HEP0102102796h05.w2kF59780SCF:363 CpG Variation 6 30050162 30050162 + . 0 NA ESME HEP0102102796h05.w2kF59780SCF:382 CpG Variation 6 30050181 30050181 + . 1 NA ESME HEP0102102796a04.w2kF59780SCF:114 CpG Variation 6 30049913 30049913 + . 25 NA ESME HEP0102102796a04.w2kF59780SCF:154 CpG Variation 6 30049953 30049953 + . 28 NA ESME HEP0102102796a04.w2kF59780SCF:170 CpG Variation 6 30049969 30049969 + . 28 NA ESME HEP0102102796a04.w2kF59780SCF:172 CpG Variation 6 30049971 30049971 + . 45 NA ESME HEP0102102796a04.w2kF59780SCF:245 CpG Variation 6 30050044 30050044 + . 29 NA ESME HEP0102102796a04.w2kF59780SCF:363 CpG Variation 6 30050162 30050162 + . 0 NA ESME HEP0102102796a04.w2kF59780SCF:382 CpG Variation 6 30050181 30050181 + . 8 NA ESME HEP0102102796e06.w2kF59780SCF:114 CpG Variation 6 30049913 30049913 + . 20 NA ESME HEP0102102796e06.w2kF59780SCF:154 CpG Variation 6 30049953 30049953 + . 28 NA ESME HEP0102102796e06.w2kF59780SCF:170 CpG Variation 6 30049969 30049969 + . 44 NA ESME HEP0102102796e06.w2kF59780SCF:172 CpG Variation 6 30049971 30049971 + . -1 NA ESME HEP0102102796e06.w2kF59780SCF:245 CpG Variation 6 30050044 30050044 + . 22 NA ESME HEP0102102796e06.w2kF59780SCF:363 CpG Variation 6 30050162 30050162 + . 0 NA ESME HEP0102102796e06.w2kF59780SCF:382 CpG Variation 6 30050181 30050181 + . 0 NA ESME HEP0102102788c04.w2kF59780SCF:32 CpG Variation 6 30049831 30049831 + . -1 NA ESME HEP0102102788c04.w2kF59780SCF:114 CpG Variation 6 30049913 30049913 + . 38 NA ESME HEP0102102788c04.w2kF59780SCF:154 CpG Variation 6 30049953 30049953 + . 31 NA ESME HEP0102102788c04.w2kF59780SCF:170 CpG Variation 6 30049969 30049969 + . 54 NA ESME HEP0102102788c04.w2kF59780SCF:172 CpG Variation 6 30049971 30049971 + . 36 NA ESME HEP0102102788c04.w2kF59780SCF:245 CpG Variation 6 30050044 30050044 + . 27 NA ESME HEP0102102788c04.w2kF59780SCF:363 CpG Variation 6 30050162 30050162 + . 0 NA ESME HEP0102102788c04.w2kF59780SCF:382 CpG Variation 6 30050181 30050181 + . 4 NA ESME HEP0102102796d06.w2kF59780SCF:32 CpG Variation 6 30049831 30049831 + . -1 NA ESME HEP0102102796d06.w2kF59780SCF:114 CpG Variation 6 30049913 30049913 + . 0 NA ESME HEP0102102796d06.w2kF59780SCF:154 CpG Variation 6 30049953 30049953 + . 15 NA ESME HEP0102102796d06.w2kF59780SCF:170 CpG Variation 6 30049969 30049969 + . 16 NA ESME HEP0102102796d06.w2kF59780SCF:172 CpG Variation 6 30049971 30049971 + . 16 NA ESME HEP0102102796d06.w2kF59780SCF:245 CpG Variation 6 30050044 30050044 + . 21 NA ESME HEP0102102796d06.w2kF59780SCF:363 CpG Variation 6 30050162 30050162 + . 0 NA ESME HEP0102102796d06.w2kF59780SCF:382 CpG Variation 6 30050181 30050181 + . 0 NA ESME HEP0102102796b05.w2kF59780SCF:32 CpG Variation 6 30049831 30049831 + . -1 NA ESME HEP0102102796b05.w2kF59780SCF:114 CpG Variation 6 30049913 30049913 + . 0 NA ESME HEP0102102796b05.w2kF59780SCF:154 CpG Variation 6 30049953 30049953 + . 17 NA ESME HEP0102102796b05.w2kF59780SCF:170 CpG Variation 6 30049969 30049969 + . 29 NA ESME HEP0102102796b05.w2kF59780SCF:172 CpG Variation 6 30049971 30049971 + . 24 NA ESME HEP0102102796b05.w2kF59780SCF:245 CpG Variation 6 30050044 30050044 + . 10 NA ESME HEP0102102796b05.w2kF59780SCF:363 CpG Variation 6 30050162 30050162 + . 0 NA ESME HEP0102102796b05.w2kF59780SCF:382 CpG Variation 6 30050181 30050181 + . 0 NA ESME HEP0102102788a06.w2kF59780SCF:32 CpG Variation 6 30049831 30049831 + . -1 NA ESME HEP0102102788a06.w2kF59780SCF:114 CpG Variation 6 30049913 30049913 + . 67 NA [[alternative HTML version deleted]]
Mike Rennie
2010-Nov-05 17:02 UTC
[R] How to extract particular rows and column from a table
Hi Mauluda, Next time, please read the posting guide- helping you is made alot easier if you provide the code that didn't work. It sounds like you might want something like this? #make a data frame, with some column names assigned... aa<-data.frame(c(rep("a",5), rep("c",3)),c(rep(7,5), rep(2,3))) aa colnames(aa)<-c("cola", "colb") aa #select your items of interest... ab<-aa$colb[aa$cola=="a"] ab HTH, Mike On Fri, Nov 5, 2010 at 11:26 AM, Mauluda Akhtar <mauluda82@gmail.com> wrote:> Hello, > I'm a new user of R. I've a very big table like the following structure > (suppose the variable name with "aa"). From this table I want to make a new > table which'll contain just two column with V2 and V6 with some particular > rows( Suppose, variable name with "bb"). I'd like to mention V2 column is > representing the id that correspond to the column V6 whis is represention > the base position of DNA. In this bb table, just for an example I want to > extract all the corresponding rows of V2 column where in V6 column there is > "30049831" (in my table there is repeatation of same base position). I > tried > this but faild to solve. > Could you please let me know how can i solve this. > > Thank you. > Mauluda > > > V1 V2 > V3 V4 V5 V6 V7 V8 V9 V10 V11 > ESME HEP0102102796h05.w2kF59780SCF:32 CpG Variation 6 > 30049831 30049831 + . -1 NA > ESME HEP0102102796h05.w2kF59780SCF:114 CpG Variation 6 > 30049913 30049913 + . 31 NA > ESME HEP0102102796h05.w2kF59780SCF:154 CpG Variation 6 > 30049953 30049953 + . 48 NA > ESME HEP0102102796h05.w2kF59780SCF:170 CpG Variation 6 > 30049969 30049969 + . 30 NA > ESME HEP0102102796h05.w2kF59780SCF:172 CpG Variation 6 > 30049971 30049971 + . 38 NA > ESME HEP0102102796h05.w2kF59780SCF:245 CpG Variation 6 > 30050044 30050044 + . 14 NA > ESME HEP0102102796h05.w2kF59780SCF:363 CpG Variation 6 > 30050162 30050162 + . 0 NA > ESME HEP0102102796h05.w2kF59780SCF:382 CpG Variation 6 > 30050181 30050181 + . 1 NA > ESME HEP0102102796a04.w2kF59780SCF:114 CpG Variation 6 > 30049913 30049913 + . 25 NA > ESME HEP0102102796a04.w2kF59780SCF:154 CpG Variation 6 > 30049953 30049953 + . 28 NA > ESME HEP0102102796a04.w2kF59780SCF:170 CpG Variation 6 > 30049969 30049969 + . 28 NA > ESME HEP0102102796a04.w2kF59780SCF:172 CpG Variation 6 > 30049971 30049971 + . 45 NA > ESME HEP0102102796a04.w2kF59780SCF:245 CpG Variation 6 > 30050044 30050044 + . 29 NA > ESME HEP0102102796a04.w2kF59780SCF:363 CpG Variation 6 > 30050162 30050162 + . 0 NA > ESME HEP0102102796a04.w2kF59780SCF:382 CpG Variation 6 > 30050181 30050181 + . 8 NA > ESME HEP0102102796e06.w2kF59780SCF:114 CpG Variation 6 > 30049913 30049913 + . 20 NA > ESME HEP0102102796e06.w2kF59780SCF:154 CpG Variation 6 > 30049953 30049953 + . 28 NA > ESME HEP0102102796e06.w2kF59780SCF:170 CpG Variation 6 > 30049969 30049969 + . 44 NA > ESME HEP0102102796e06.w2kF59780SCF:172 CpG Variation 6 > 30049971 30049971 + . -1 NA > ESME HEP0102102796e06.w2kF59780SCF:245 CpG Variation 6 > 30050044 30050044 + . 22 NA > ESME HEP0102102796e06.w2kF59780SCF:363 CpG Variation 6 > 30050162 30050162 + . 0 NA > ESME HEP0102102796e06.w2kF59780SCF:382 CpG Variation 6 > 30050181 30050181 + . 0 NA > ESME HEP0102102788c04.w2kF59780SCF:32 CpG Variation 6 > 30049831 30049831 + . -1 NA > ESME HEP0102102788c04.w2kF59780SCF:114 CpG Variation 6 > 30049913 30049913 + . 38 NA > ESME HEP0102102788c04.w2kF59780SCF:154 CpG Variation 6 > 30049953 30049953 + . 31 NA > ESME HEP0102102788c04.w2kF59780SCF:170 CpG Variation 6 > 30049969 30049969 + . 54 NA > ESME HEP0102102788c04.w2kF59780SCF:172 CpG Variation 6 > 30049971 30049971 + . 36 NA > ESME HEP0102102788c04.w2kF59780SCF:245 CpG Variation 6 > 30050044 30050044 + . 27 NA > ESME HEP0102102788c04.w2kF59780SCF:363 CpG Variation 6 > 30050162 30050162 + . 0 NA > ESME HEP0102102788c04.w2kF59780SCF:382 CpG Variation 6 > 30050181 30050181 + . 4 NA > ESME HEP0102102796d06.w2kF59780SCF:32 CpG Variation 6 > 30049831 30049831 + . -1 NA > ESME HEP0102102796d06.w2kF59780SCF:114 CpG Variation 6 > 30049913 30049913 + . 0 NA > ESME HEP0102102796d06.w2kF59780SCF:154 CpG Variation 6 > 30049953 30049953 + . 15 NA > ESME HEP0102102796d06.w2kF59780SCF:170 CpG Variation 6 > 30049969 30049969 + . 16 NA > ESME HEP0102102796d06.w2kF59780SCF:172 CpG Variation 6 > 30049971 30049971 + . 16 NA > ESME HEP0102102796d06.w2kF59780SCF:245 CpG Variation 6 > 30050044 30050044 + . 21 NA > ESME HEP0102102796d06.w2kF59780SCF:363 CpG Variation 6 > 30050162 30050162 + . 0 NA > ESME HEP0102102796d06.w2kF59780SCF:382 CpG Variation 6 > 30050181 30050181 + . 0 NA > ESME HEP0102102796b05.w2kF59780SCF:32 CpG Variation 6 > 30049831 30049831 + . -1 NA > ESME HEP0102102796b05.w2kF59780SCF:114 CpG Variation 6 > 30049913 30049913 + . 0 NA > ESME HEP0102102796b05.w2kF59780SCF:154 CpG Variation 6 > 30049953 30049953 + . 17 NA > ESME HEP0102102796b05.w2kF59780SCF:170 CpG Variation 6 > 30049969 30049969 + . 29 NA > ESME HEP0102102796b05.w2kF59780SCF:172 CpG Variation 6 > 30049971 30049971 + . 24 NA > ESME HEP0102102796b05.w2kF59780SCF:245 CpG Variation 6 > 30050044 30050044 + . 10 NA > ESME HEP0102102796b05.w2kF59780SCF:363 CpG Variation 6 > 30050162 30050162 + . 0 NA > ESME HEP0102102796b05.w2kF59780SCF:382 CpG Variation 6 > 30050181 30050181 + . 0 NA > ESME HEP0102102788a06.w2kF59780SCF:32 CpG Variation 6 > 30049831 30049831 + . -1 NA > ESME HEP0102102788a06.w2kF59780SCF:114 CpG Variation 6 > 30049913 30049913 + . 67 NA > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Michael Rennie, Research Scientist Fisheries and Oceans Canada, Freshwater Institute Winnipeg, Manitoba, CANADA [[alternative HTML version deleted]]