An archived instance of Mark's Discourse site as of Tuesday July 18, 2017.

Computing statistical measures in R

audrey

Well, I am awfully confused about how to compute statistical measures of data in R - things, like mean, median, variance, and standard deviation. I can do things by hand but I just can't find the proper commands in R.

For example, suppose I have the following random list of numbers:

12, 24,  6,  5, 30, 14, 12, 17, 19

It's easy enough to compute the mean to be:

$$\bar{x} = \frac{12 + 24 + 6 + 5 + 30 + 14 + 12 + 17 + 19}{9} = \frac{139}{9} = 15.\overline{4}.$$

I can compute the standard deviation with a bit more work but what are the R command to do this?

FRD

First, you will have to create a list with the values you were given using the following command:
nameOfYourList<-c(Put your values inside these parenthesis separated by commas)
Now, all you have to do is to write the following:
For the mean:
mean(nameOfYourList)
For the median:
median(nameOfYourList)
For the variance:
var(nameOfYourList)
For the standard deviation:
sd(nameOfYourList)
I hope this helps. Good luck










mark

@FRD I like your answer, though, you could probably make your response even more explicit. To compute the standard deviation, for example, you could type:

sd(c(12, 24,  6,  5, 30, 14, 12, 17, 19))
# Out: 8.094923