search for: meanbygroup

Displaying 1 result from an estimated 1 matches for "meanbygroup".

2009 Mar 25
2
"with" and "by" and NA:
...variables for which I am performing the mean by subgroup, for a pair of variables at a time, where one of them for each pair defines the subgroup. The subgroups in the x$cm1 are 0, 1 and 2. x ph1 cm1 0.2345 2 1.2222 1 2.0033 0 0.0000 2 1.0033 1 0.2345 0 1.2222 2 2.0033 0 0.0000 1 1.0033 2 > meanbygroup <- as.vector(with(x, by(x$ph1, x$cm1, mean))) > meanbygroup if the ph1 has no missing values the above statements work fine: [1] 1.4137000 0.7418333 0.6150000 In the moment that I introduce in the ph1 a missing value in the ph1 as NA x ph1 cm1 0.2345 2 NA 1 1.2222 1 ............. the...