[R] Selecting rows according to a column
Erik Iverson
eiverson at NMDP.ORG
Wed Oct 28 17:22:09 CET 2009
Hello,
Here's an idea:
ifelse(z$c == "a", z$a, z$b)
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Gurpal Kalsi
> Sent: Wednesday, October 28, 2009 11:15 AM
> To: r-help at r-project.org
> Subject: [R] Selecting rows according to a column
>
> Hi,
>
> With a data such as:
> > z = data.frame(a = 1:5, b=10*a, c = c("a", "a", "b", "b", "b") )
> * a b c*
> *1* 10 *a*
> *2* 20 *a*
> 3 *30* *b*
> 4 *40* *b*
> 5 *50* *b*
>
> Can anyone suggest a way to select [1, 2, 30, 40, 50],
> ie. using column "c" to specify which column is selected for each row.
>
> Many thanks
>
> G
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list