[R] how can i calculate the mean of my data which is only bigger than 75?

R. Michael Weylandt michael.weylandt at gmail.com
Wed Feb 1 21:47:16 CET 2012


I'm not entirely sure what you mean, but it's likely one of these:

apply(data, 2, function(x) mean(x[x>75]))
mean(data[ apply(data,1, function(x) all(x > 75), ])
mean(data[data>75])

Three questions to give more concrete help:

i) Is your data set stored as a matrix or a data.frame
ii) What are you trying to get the mean of -- all variables pooled or
of each variable independently?
iii) When you say >=75 for all variables, do you mean only use a row
if it's >=75 for each element or just only use the >=75 elements for
each calculation independently.

Michael

On Wed, Feb 1, 2012 at 2:38 PM, Yakamu Yakamu <iam_yakamu at yahoo.com> wrote:
> hi,
> I have a dataset with more than 15000 data and would like to calculate the mean for only those that is bigger than and equal to 75 for all variables (x,y,z1,z2,u,v,w z1 and z2).
> my dataset is (for example) as follows :
> x y z1 z2 u v w1 w2
> 95 83 57 50 59 39 90 48
> 100 92 83 82 93 92 50 50
> 39 40 59 68 59 49 60 89
> 80 80 79 57 70 79 50 79
> 78 88 98 67 79 89 79 90
> and so on...
> any help would be appreciated,
> big thanks in advance,
> Yakamu
>        [[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