?subset is probably what you want: subset(x, x1 == 'A')
On Oct 2, 1:43 pm, Kavitha Venkatesan <kavitha.venkate...@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...@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. ______________________________________________ R-help@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.