Let us practice with some functions of R

[This article was first published on Statistic on aiR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Given the following data set, compute the arithmetic mean, median, variance, standard deviation; find the greatest and the smaller value, the sum of all values, the square of the sum of all values, the sum of the square of all values; assigne the ranks and add them, assigning the ranks to the first 6 values and add those.

10, 2, 19, 24, 6, 23, 47, 24, 54, 77


Extremely simple to perform in R, deliberately created to familiarize with some statistical functions that can serve us in the future. Not carry over mathematical formulas, which you can find in any book of mathematics, or Wikipedia.

a = c(10, 2, 19, 24, 6, 23, 47, 24, 54, 77)

mean(a) #calculate the arithmetic mean
[1] 28.6

median(a) #calculate the median
[1] 23.5

var(a) #calculate the variance
[1] 561.8222

sd(a) #calculate the standard deviation
[1] 23.70279

max(a) #shows the larger value of the sequence
[1] 77

min(a) #shows the smallest value of the sequence
[1] 2

sum(a) #sum all the values
[1] 286

sum(a)*sum(a) #calculates the square of the sum of all values
[1] 81796

sum(a*a) #calculates the sum of the squares of all values
[1] 13236

sum(rank(a)) #sum of ranks assigned to the variables contained in a
[1] 55

sum(rank(a)[1:6]) #sum of ranks assigned to the first 6 values of a
[1] 21.5

To leave a comment for the author, please follow the link and comment on their blog: Statistic on aiR.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)