RE: [R] retrieve rows from frame assuming criterion [corrected]

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Sat 24 Jul 2004 - 00:22:06 EST


Still wrong:

> x <- data.frame(a = sample(letters[1:3], 10, replace=T), b=1:10)
> x

   a b
1 a 1
2 a 2
3 b 3
4 b 4
5 a 5
6 a 6
7 b 7
8 b 8
9 b 9
10 c 10
> subset(x, a == c("b", "c"))

   a b
3 b 3
7 b 7
9 b 9
10 c 10
> subset(x, a %in% c("b", "c"))

   a b
3 b 3
4 b 4
7 b 7
8 b 8
9 b 9
10 c 10

What matters is the use of "%in%" instead of "==", not the use of subset().

Andy

> From: Guazzetti Stefano
>
> sorry for my previus (WRONG)
> answer, as someone already pointed out
> a solution could be
>
> subset(data, PUNTAR==c("IX49","IX48"))
>
>
>
> > -----Messaggio originale-----
> > Da: Guazzetti Stefano
> > Inviato: venerdý 23 luglio 2004 15.55
> > A: 'Luis Rideau Cruz'; r-help@stat.math.ethz.ch
> > Oggetto: R: [R] retrieve rows from frame assuming criterion
> >
> >
> > Assuming your data.frame is called "data"
> >
> > data[data$PUNTAR==c("IX49","IX48"),]
> >
> > is probably what you want
> >
> > Stefano
> >
> >
> >
> > > -----Messaggio originale-----
> > > Da: Luis Rideau Cruz [mailto:Luisr@frs.fo]
> > > Inviato: venerdý 23 luglio 2004 15.37
> > > A: r-help@stat.math.ethz.ch
> > > Oggetto: [R] retrieve rows from frame assuming criterion
> > >
> > >
> > > 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@frs.fo
> > > Web: www.frs.fo
> > >
> > > ______________________________________________
> > > R-help@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.html
> >
>
> ______________________________________________
> R-help@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.html
>
>



R-help@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.html Received on Sat Jul 24 00:32:43 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:12 EST