Mean function not giving the correct answer in R



I wrote a command to calculate mean


and I am getting the output as

[1] 2

Why is this happening and why is the first value getting returned instead of the mean?


hello @pravin,

If you are using R then you have to use:


Hope this helps!!


@pravin, if you look at the mean function’s help page (?mean from the R coammnd line), you’ll notice that the function calculates the mean of a particular R object which should be provided as the first argument (if you are not using keywords). In you case it happens to be a numeric–a single digit, whereas what you wish to find out is the mean of 2, 20 and 26. So to do that you must provide them in a concatenated form (i.e. a vector), as shown by @shuvayan.

And remember, always RTM. :smile:

(However, I’m not sure about why it does not complain about the validity, of lack thereof, of the other two arguments.)