`means` does not give the correct answer

Like above, does anyone know what is going on?

m1 <- 0.457842055395572 m2 <- 0.587127416942505 sum(m1, m2)/2 mean(m1, m2) 

Output:

 > m1 <- 0.457842055395572 > m2 <- 0.587127416942505 > sum(m1, m2)/2 [1] 0.5224847 > mean(m1, m2) [1] 0.4578421 

Restarting R and all the same. Am on R 3.0 x86 Windows.

+4
source share
1 answer

mean is a function S3 that takes a single main argument, which is a single object R (most often a vector) of quantities, and any other arguments are passed to other methods through ... In this case, they are passed to mean.default , which has two additional named arguments, trim and na.rm Therefore, your second value will be interpreted as the sum of the trim (although you cannot trim a single value).

What do you want to print:

 mean(c(m1, m2)) [1] 0.5224847 
+7
source

Source: https://habr.com/ru/post/1480898/


All Articles