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. Any ideas? Thanks a lot! Dax.
Look at ?subset. Sean On Jan 28, 2005, at 1:26 PM, dax42 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. > > Any ideas? > Thanks a lot! > Dax. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
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.
newdat <- subset(a, a$V3 == "O") ?subset dax42 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. > > Any ideas? > Thanks a lot! > Dax. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894