[R] how to recode with an if-type statement

2009-09-14 Thread Casey Klofstad
I'm sure this is easy, but I'm having a hard time figuring out how to recode some data in R. I have a variable numpeers which is valued 1, 2, or 3. I also have three other variables called w9zd9_1, w9zd9_2, and w9zd9_3. I want to use these variables to create a new item called distot.

[R] group mean, minus each row's value

2007-11-13 Thread Casey Klofstad
I used the following to assign each row the group average, where w is the new group average variable, x is the variabale to be averaged, and g is the nominal group indicator: w - ave(x,g) Now I want to calculate the group average, but WITHOUT each row's value of x. Is there an easy way to do

[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