[R] extracting from a data.frame

Duncan Murdoch murdoch at stats.uwo.ca
Fri Jan 28 19:32:44 CET 2005


On Fri, 28 Jan 2005 19:26:14 +0100, dax42 <Dax42 at web.de> wrote :

>Hi,
>
>I am sorry for this simple question, but... How do I extract something 
>from a data.frame?
>The following is my Problem:
>I have got a dataframe "a" with various columns. One of those columns 
>is called V3 and contains elements of the following levels:
>
> > levels(a$V3)
>  [1] "C"   "CA"  "CB"  "CD"  "CD1" "CD2" "CE"  "CE1" "CE2" "CE3" "CG"
>[12] "CG1" "CG2" "CH2" "CZ"  "CZ2" "CZ3" "N"   "ND1" "ND2" "NE"  "NE1"
>[23] "NE2" "NH1" "NH2" "NZ"  "O"   "OD1" "OD2" "OE1" "OE2" "OG"  "OG1"
>[34] "OH"  "OXT" "SD"  "SG"
>
>Now I would like to get all rows of a, that have the value "O" in V3.
>I tried a lot of different combinations of [... but I couldn't make it.

a[a$V3 == "O", ]

or 

with(a, a[V3 == "O", ])

which makes more sense when the selection expression is more
complicated, because you don't need the a$ prefix on every column.

Duncan Murdoch

P.S. your return address fails.




More information about the R-help mailing list