[R] split-apply question
andrew
andrewjohnroyal at gmail.com
Fri Oct 2 06:53:53 CEST 2009
?subset is probably what you want:
subset(x, x1 == 'A')
On Oct 2, 1:43 pm, Kavitha Venkatesan <kavitha.venkate... at gmail.com>
wrote:
> Hi,
>
> I have a data frame that looks like this:
>
> >x
>
> x1 x2 x3
> A 1 1.5
> B 2 0.9
> B 3 2.7
> C 7 1.8
> D 7 1.3
>
> I want to "group" by the x1 column and in the case of multiple x$x1 values
> (e.g., "B")d, return rows that have the smallest values of x2. In the case
> of rows with only one value of x1 (e.g., "A"), return the row as is. How can
> I do that? For example, in the above case, the output I want would be:
>
> x1 x2 x3
> A 1 1.5
> B 2 0.9
> C 7 1.8
> D 7 1.3
>
> Thanks!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list