[R] Extrcat selected rows from a list
Petr Savicky
savicky at praha1.ff.cuni.cz
Tue Feb 8 18:08:17 CET 2011
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.
More information about the R-help
mailing list