[R] Mean error
arun
smartpink111 at yahoo.com
Tue Oct 29 22:06:55 CET 2013
Hi,
Try either:
res1 <- apply(mydata[,1:2],2,mean)
res2 <- colMeans(mydata[,1:2])
identical(res1,res2)
#[1] TRUE
# Also if you need to find means for each group ("Ungrazed vs. "Grazed")
by(mydata[,-3],mydata[,3],colMeans)
#or if column names are "V1", "V2", "V3"
aggregate(.~V3,mydata,mean)
#or
library(plyr)
ddply(mydata,.(V3),numcolwise(mean))
A.K.
I have a data set with two columns of data that I want to find the mean of.
1 6.225 59.77 Ungrazed
2 6.487 60.98 Ungrazed
3 4.919 14.73 Ungrazed
4 5.130 19.28 Ungrazed
5 5.417 34.25 Ungrazed
6 5.359 35.53 Ungrazed
7 7.614 87.73 Ungrazed
8 6.352 63.21 Ungrazed
9 4.975 24.25 Ungrazed
10 6.930 64.34 Ungrazed
11 6.248 52.92 Ungrazed
12 5.451 32.35 Ungrazed
13 6.013 53.61 Ungrazed
14 5.928 54.86 Ungrazed
15 6.264 64.81 Ungrazed
16 7.181 73.24 Ungrazed
17 7.001 80.64 Ungrazed
18 4.426 18.89 Ungrazed
19 7.302 75.49 Ungrazed
20 5.836 46.73 Ungrazed
21 10.253 116.05 Ungrazed
22 6.958 38.94 Grazed
23 8.001 60.77 Grazed
24 9.039 84.37 Grazed
25 8.910 70.11 Grazed
26 6.106 14.95 Grazed
27 7.691 70.70 Grazed
28 8.988 80.31 Grazed
29 8.975 82.35 Grazed
30 9.844 105.07 Grazed
31 8.508 73.79 Grazed
32 7.354 50.08 Grazed
33 8.643 78.28 Grazed
34 7.916 41.48 Grazed
35 9.351 98.47 Grazed
36 7.066 40.15 Grazed
37 8.158 52.26 Grazed
38 7.382 46.64 Grazed
39 8.515 71.01 Grazed
40 8.530 83.03 Grazed
This is from an introduction handout that instructs me to enter the command
>mean(mydata[,1:2])
but when I enter it, I get an error message
Warning message:
In mean.default(mydata[, 1:2]) :
argument is not numeric or logical: returning NA
I've tried tacking on na.rm=T to the end of it, but I get the same
message. Can someone tell me what I'm doing wrong, or how to fix it?
I've tried searching the forum, but can't find a post relevant to this problem.
More information about the R-help
mailing list