-
> Van: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] Namens William Dunlap
> Verzonden: woensdag 22 september 2010 19:51
> Aan: Seth W Bigelow; bill.venab...@csiro.au
> CC: r-help@r-project.org
> Onderwerp: Re: [R] Doing operations by grouping variable
>
ge-
>> From: r-help-boun...@r-project.org
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Seth W Bigelow
>> Sent: Tuesday, September 21, 2010 4:22 PM
>> To: bill.venab...@csiro.au
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Doing operations by gro
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Seth W Bigelow
> Sent: Tuesday, September 21, 2010 4:22 PM
> To: bill.venab...@csiro.au
> Cc: r-help@r-project.org
> Subject: Re: [R] Doing operations
cific Southwest Research Station
1731 Research Park Drive, Davis California
09/21/2010 03:15 PM
To
cc
,
Subject
RE: [R] Doing operations by grouping variable
You left out the subscript. Why not just do
d <- within(data.frame(group = rep(1:5, each = 5), variable =
.bedw...@gmail.com; r-help@r-project.org
Subject: RE: [R] Doing operations by grouping variable
Thanks, Bill and Michael, you have answered the question I asked, but not the
one I wished to ask I want to obtain the maximum in each group of variables, so
I could scale each variable by the maximu
Seth W Bigelow" , "R-help"
cc
Subject
RE: [R] Doing operations by grouping variable
Have you tried using ave()?
group <- rep(1:5,each=5)
variable <- log(1:25)
d <- data.frame(group, variable)
d$scaled <- d$variable/with(d, ave(variable, group, FUN=max)
: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Seth W Bigelow
> Sent: Tuesday, September 21, 2010 8:43 AM
> To: bill.venab...@csiro.au
> Cc: r-help@r-project.org
> Subject: Re: [R] Doing operations by grouping variable
>
> Thanks, Bill and Mi
d using attach().)
Bill Venables.
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Michael Bedward
Sent: Tuesday, 21 September 2010 11:15 AM
To: Seth W Bigelow; Rhelp
Subject: Re: [R] Doing operations by grouping variable
Not sure
ginal Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Michael Bedward
Sent: Tuesday, 21 September 2010 11:15 AM
To: Seth W Bigelow; Rhelp
Subject: Re: [R] Doing operations by grouping variable
Not sure why you think tapply is "awkward"
Not sure why you think tapply is "awkward". Your example would be...
group <- rep(1:5, each=5)
variable <- rnorm(25)
tapply(variable, group, max)
...which looks quite elegant to me :)
Meanwhile, the reason your expression doesn't work is that you are
asking mistakenly for elements 1:5 repeatedly
I'm writing an expression that requires searching a vector according to
group. As an example, I want to find the maximum value in each of 5
groups.
group=rep(1:5, each=5) # create grouping variable
variable=rnorm(25) # generate data
d <-
11 matches
Mail list logo