[R] finding unique and max value from a data.frame
Srinivas Iyyer
srini_iyyer_bio at yahoo.com
Fri Oct 24 02:52:40 CEST 2008
Hi Jim,
thank you for tip. However, why it works for you and the same line fails in my R.
> myx <-x
> myx
x1 x2
1 a 4
2 b 3
3 c 2
4 a 1
5 c 2
6 f 3
7 g 4
8 f 5
> aggregate(x=myx$x2,by =list(myx$x1),max)
Error in Summary.factor(c(4L, 1L), na.rm = FALSE) :
max not meaningful for factors
Thank you.
--- On Thu, 10/23/08, jim holtman <jholtman at gmail.com> wrote:
> From: jim holtman <jholtman at gmail.com>
> Subject: Re: [R] finding unique and max value from a data.frame
> To: srini_iyyer_bio at yahoo.com
> Cc: R-help at stat.math.ethz.ch
> Date: Thursday, October 23, 2008, 8:41 PM
> ?aggregate
>
> x1 x2
> 1 a 4
> 2 b 3
> 3 c 2
> 4 a 1
> 5 c 2
> 6 f 3
> 7 g 4
> 8 f 5
> > aggregate(x$x2, list(x$x1), max)
> Group.1 x
> 1 a 4
> 2 b 3
> 3 c 2
> 4 f 5
> 5 g 4
> >
>
>
> On Thu, Oct 23, 2008 at 8:30 PM, Srinivas Iyyer
> <srini_iyyer_bio at yahoo.com> wrote:
> > Hi group,
> >
> > How can I identify an element with max value among
> duplicated elements all in a data frame
> >
> > Example:
> >
> >> x1
> > x1 x2
> > 1 a 4
> > 2 b 3
> > 3 c 2
> > 4 a 1
> > 5 c 2
> > 6 f 3
> > 7 g 4
> > 8 f 5
> >
> >
> > I want to be able to get a data frame with all
> unique(x1) with max value
> >
> > x1 x2
> > 1 a 4
> > 2 b 3
> > 3 c 2
> > 5 c 2
> > 7 g 4
> > 8 f 5
> >
> >
> > Could I get some help please.
> > thanks
> > srini
> >
> > ______________________________________________
> > 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.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
More information about the R-help
mailing list