Re: [R] how to assign a group mean to individual cases?

2007-11-15 Thread Greg Snow
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

Re: [R] how to assign a group mean to individual cases?

2007-11-13 Thread Emmanuel Charpentier
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

Re: [R] how to assign a group mean to individual cases?

2007-11-13 Thread Emmanuel Charpentier
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

Re: [R] how to assign a group mean to individual cases?

2007-11-12 Thread Moshe Olshansky
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

Re: [R] how to assign a group mean to individual cases?

2007-11-12 Thread Gabor Grothendieck
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

[R] how to assign a group mean to individual cases?

2007-11-12 Thread Casey Klofstad
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