Hi all,
I have a data frame in which one column(PUNTAR) is of character type.
What I want is to retrieve is the frame but only with those rows matching
elements of PUNTAR with a list characters (e.g
c("IX49","IX48") )
Year TUR STODNR PUNTAR
1994 9412 94020061 IX49
1994 9412 94020062 IX48
1994 9412 94020063 X32
1994 9412 94020065 X23
1994 9412 94020066 X27
1994 9412 94020067 XI19
1994 9412 94020068 XI16
1994 9412 94020069 XI14
1994 9412 94020070 XI8
1994 9412 94020071 X25
1994 9412 94020072 X18
1994 9412 94020073 II23
1994 9412 94020074 XII33
1994 9412 94020075 XII31
"my.function"("frame") should be then equal to
Year TURNR STODNR M_PUNTAR
1994 9412 94020061 IX49
1994 9412 94020062 IX48
Thank you in advance
Luis Ridao Cruz
Fiskiranns??knarstovan
N??at??n 1
P.O. Box 3051
FR-110 T??rshavn
Faroe Islands
Phone: +298 353900
Phone(direct): +298 353912
Mobile: +298 580800
Fax: +298 353901
E-mail: luisr at frs.fo
Web: www.frs.fo
?subset Eryk *********** REPLY SEPARATOR *********** On 7/23/2004 at 2:36 PM Luis Rideau Cruz wrote:>>>Hi all, >>> >>>I have a data frame in which one column(PUNTAR) is of character type. >>>What I want is to retrieve is the frame but only with those rows >>>matching elements of PUNTAR with a list characters (e.g c("IX49","IX48") >>>) >>> >>>Year TUR STODNR PUNTAR >>>1994 9412 94020061 IX49 >>>1994 9412 94020062 IX48 >>>1994 9412 94020063 X32 >>>1994 9412 94020065 X23 >>>1994 9412 94020066 X27 >>>1994 9412 94020067 XI19 >>>1994 9412 94020068 XI16 >>>1994 9412 94020069 XI14 >>>1994 9412 94020070 XI8 >>>1994 9412 94020071 X25 >>>1994 9412 94020072 X18 >>>1994 9412 94020073 II23 >>>1994 9412 94020074 XII33 >>>1994 9412 94020075 XII31 >>> >>>"my.function"("frame") should be then equal to >>> >>>Year TURNR STODNR M_PUNTAR >>>1994 9412 94020061 IX49 >>>1994 9412 94020062 IX48 >>> >>>Thank you in advance >>> >>> >>>Luis Ridao Cruz >>>Fiskiranns??knarstovan >>>N??at??n 1 >>>P.O. Box 3051 >>>FR-110 T??rshavn >>>Faroe Islands >>>Phone: +298 353900 >>>Phone(direct): +298 353912 >>>Mobile: +298 580800 >>>Fax: +298 353901 >>>E-mail: luisr at frs.fo >>>Web: www.frs.fo >>> >>>______________________________________________ >>>R-help at stat.math.ethz.ch mailing list >>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help >>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlDipl. bio-chem. Eryk Witold Wolski @ MPI-Moleculare Genetic Ihnestrasse 63-73 14195 Berlin 'v' tel: 0049-30-83875219 / \ mail: wolski at molgen.mpg.de ---W-W---- http://www.molgen.mpg.de/~wolski
On Fri, 2004-07-23 at 08:36, Luis Rideau Cruz wrote:> Hi all, > > I have a data frame in which one column(PUNTAR) is of character type. > What I want is to retrieve is the frame but only with those rows > matching elements of PUNTAR with a list characters (e.g > c("IX49","IX48") ) > > Year TUR STODNR PUNTAR > 1994 9412 94020061 IX49 > 1994 9412 94020062 IX48 > 1994 9412 94020063 X32 > 1994 9412 94020065 X23 > 1994 9412 94020066 X27 > 1994 9412 94020067 XI19 > 1994 9412 94020068 XI16 > 1994 9412 94020069 XI14 > 1994 9412 94020070 XI8 > 1994 9412 94020071 X25 > 1994 9412 94020072 X18 > 1994 9412 94020073 II23 > 1994 9412 94020074 XII33 > 1994 9412 94020075 XII31 > > "my.function"("frame") should be then equal to > > Year TURNR STODNR M_PUNTAR > 1994 9412 94020061 IX49 > 1994 9412 94020062 IX48 > > Thank you in advanceFor a simple subset like this, something like the following, presuming that your data frame is called MyData: MyData[MyData$PUNTAR %in% c("IX49", "IX48"), ] Year TUR STODNR PUNTAR 1 1994 9412 94020061 IX49 2 1994 9412 94020062 IX48 This basically says to select only those rows where the value of MyData$PUNTAR is in c("IX49", "IX48"). If you need to engage in more complex boolean comparisons for subsetting, especially on multiple columns, then the function subset() would be better suited. HTH, Marc Schwartz