[R] (sans objet)

Duncan Murdoch murdoch.duncan at gmail.com
Fri Oct 4 00:53:16 CEST 2013


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



More information about the R-help mailing list