are
[EMAIL PROTECTED]
(801) 408-8111
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Casey Klofstad
> Sent: Monday, November 12, 2007 3:02 PM
> To: r-help@r-project.org
> Subject: [R] how to assign a group mean to individual case
Answering to myself...
Emmanuel Charpentier a écrit :
> Casey Klofstad a écrit :
>> I need advice on how to create a variable that is the group mean of
>> another variable.
>>
>> For example, I have a variable called x for which each row in the data
>> set has a value. I also have a nominal variabl
Casey Klofstad a écrit :
> I need advice on how to create a variable that is the group mean of
> another variable.
>
> For example, I have a variable called x for which each row in the data
> set has a value. I also have a nominal variable called g that
> indicates which of 100 different groups ea
You can do the following:
x <- 1:10
g <- rep(3:5,len=10)
df <- data.frame(g=g,x=x)
y <- aggregate(df$x,list(df$g))
z <- sapply(df$g,function(x) which(y[,1]==x))
df1 <- data.frame(df,group.mean=y[z,2])
--- Casey Klofstad <[EMAIL PROTECTED]> wrote:
> I need advice on how to create a variable that
Look at:
?ave
On Nov 12, 2007 5:01 PM, Casey Klofstad <[EMAIL PROTECTED]> wrote:
> I need advice on how to create a variable that is the group mean of
> another variable.
>
> For example, I have a variable called x for which each row in the data
> set has a value. I also have a nominal variable c
I need advice on how to create a variable that is the group mean of
another variable.
For example, I have a variable called x for which each row in the data
set has a value. I also have a nominal variable called g that
indicates which of 100 different groups each row belongs to.
So, I want to cre
6 matches
Mail list logo