[R] computing the mean of a few variables
Tobias Verbeke
tobias.verbeke at telenet.be
Thu Nov 1 10:14:40 CET 2007
sigalit mangut-leiba wrote:
> I want to compute the average of 6 variables,
> my data looks like this:
>
> t0 t1 t2 t3 t4 t5
> 1 32 34 36 40 38 40
> 2 35 37 38 36 33 39
> .
> .
> .
> I want the mean of t0-t5 for each row (observation).
If your data are available in a matrix mymat,
you can use
apply(mymat, 1, mean) # see ?apply
or (more efficient)
rowMeans(mymat)
HTH,
Tobias
> thank you,
> sigalit.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
>
More information about the R-help
mailing list