Hi, I have two lists 1) List1- 30,000 rows and 104 columns 2) List2- a list of 14000 selected rownames from List 1 Now, I want to extract all the 104 columns of List1 matching with the 14000 selected rownames from List2. Psedocode will be something like this: match rownames(List2) with rownames(List1) extract selected matched 104 coloumns from (List1) strore in-> List3 So the resulting List3 will contain 14,000 rows and 104 coloumns. How do I do it in R ? Regards, P Barah Department of Biology, Norwegian University of Science & Technology (NTNU) Realfagbygget, N-7491 Trondheim, Norway [[alternative HTML version deleted]]
On Tue, Feb 08, 2011 at 08:27:38PM +0530, pankaj borah wrote:> Hi, > > I have two lists > > 1) List1- 30,000 rows and 104 columns > > 2) List2- a list of 14000 selected rownames? from List 1 > > Now, I want to extract all the 104 columns of List1? matching with the 14000 selected rownames from List2.? > > Psedocode will be something like this: > match rownames(List2) with rownames(List1) > extract selected matched 104 coloumns from (List1) > strore in-> List3 > > So the resulting List3 will contain 14,000 rows and 104 coloumns. > > How do I do it in R ?Hi. Let me use a small example df <- data.frame(a=1:7, b=11:17, row.names=letters[1:7]) df a b a 1 11 b 2 12 c 3 13 d 4 14 e 5 15 f 6 16 g 7 17 Is the following what you are asking for in terms of this small example? df[c("b", "c", "g"), ] a b b 2 12 c 3 13 g 7 17 Petr Savicky.
Hi: Try some modification of the following toy example: df <- data.frame(names = as.character(replicate(100, paste(sample(letters, 3), collapse = ''))), x1 = rnorm(100), x2 = rnorm(100)) tgts <- sample(df$names, 20) # target list of names df[df$names %in% tgts, ] # yields a 20 row data frame HTH, Dennis On Tue, Feb 8, 2011 at 6:57 AM, pankaj borah <pankajborah2k3@yahoo.co.in>wrote:> Hi, > > I have two lists > > 1) List1- 30,000 rows and 104 columns > > 2) List2- a list of 14000 selected rownames from List 1 > > Now, I want to extract all the 104 columns of List1 matching with the > 14000 selected rownames from List2. > > Psedocode will be something like this: > match rownames(List2) with rownames(List1) > extract selected matched 104 coloumns from (List1) > strore in-> List3 > > So the resulting List3 will contain 14,000 rows and 104 coloumns. > > How do I do it in R ? > > > > Regards, > > P Barah > Department of Biology, > Norwegian University of Science & Technology (NTNU) > Realfagbygget, N-7491 Trondheim, Norway > > > > [[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 > and provide commented, minimal, self-contained, reproducible code. > >[[alternative HTML version deleted]]