On 13-10-03 6:42 PM, Jesse Gervais wrote:
Hello there,

I try to construct a variable with R, but I have some difficulties.

Assume that I use a data set named = mydata. I want to create a variable
that is the mean (totmean) or the sum (totsum) of 6 variables (var1, var2,
var3, var4, var5, var6). However, I want only participants who have
responded to at least 4 items to be include. Those who have one or two
missing for var1-var6 should be coded NA for totmean and totsum.

How I do that?


Write a function that computes what you want for a vector of 6 values. Then put the data into an array, and use apply( the_array, 1, your_function) to compute it for the full dataset.

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to