Lost Lost - 27 days ago 8
R Question

Different Means for Same Data R

I am trying to get the means of three sections of a particular column. As seen below, I've separated the data into the three sections by row and found the means

> x<-mydata[1:50,3]
> mean(x)
[1] 1.462
> za<-mydata[51:100,3]
> mean(za)
[1] 4.26
> ch<-mydata[101:150,3]
> mean(ch)
[1] 5.552


I tried to put this into one statement, but the means come out different than those of the separate statements.

mydata[c(mean(1:50), mean(51:100), mean(101:150)), 3]
[1] 1.9 4.3 5.7


The second mean seems rounded to the tenths place compared to the original mean, but the same cannot be said for the other two means. Is there something happening within the concatenate function that would change the means?

Answer Source

Try this:

c(mean(mydata[1:50,3]), mean(mydata[51:100,3], mean(mydata[101:150,3])