I have found following problem: I have a vector:> a <- c(1.04,1.04,1.05,1.04,1.04)I want a mean of this vector:> mean(a)[1] 1.042 which is correct, but:> mean(1.04,1.04,1.05,1.04,1.04)[1] 1.04 gives an incorrect value. how is this possible? thanks, zbynek -- View this message in context: http://r.789695.n4.nabble.com/Incorrectness-of-mean-tp3327701p3327701.html Sent from the R help mailing list archive at Nabble.com.
Oh, I see it now. I guess it confused me, when it did not give me warning and also the numbers were very much alike, so I expected wrong decimal places thanks zbynek -- View this message in context: http://r.789695.n4.nabble.com/Incorrectness-of-mean-tp3327701p3327714.html Sent from the R help mailing list archive at Nabble.com.
On 02/28/2011 09:07 PM, zbynek.janoska at gmail.com wrote:> I have found following problem: > I have a vector: >> a<- c(1.04,1.04,1.05,1.04,1.04) > I want a mean of this vector: >> mean(a) > [1] 1.042 > which is correct, but: >> mean(1.04,1.04,1.05,1.04,1.04) > [1] 1.04 > gives an incorrect value. > how is this possible?Hi Zbynek, You're asking the function to give you the mean of a single value. Try this: mean(c(1.04,1.04,1.05,1.04,1.04)) Jim
On 02/28/2011 11:07 AM, zbynek.janoska at gmail.com wrote:> I have found following problem: I have a vector: >> a<- c(1.04,1.04,1.05,1.04,1.04) > I want a mean of this vector: >> mean(a) > [1] 1.042 which is correct, but: >> mean(1.04,1.04,1.05,1.04,1.04) > [1] 1.04 gives an incorrect value. how is this possible?the x that is averaged is only the first 1.04, the other numbers go into mean's ... argument and are ignored. Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Universit? degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbeleites at units.it