R  Statistical Functions
RStudio Code 
Examples 
Function 
x = 1:10 

Creates a sequence x from 1 to 10 
length(x) 

Number of values in dataset x 
max(x) 

Largest number in dataset x 
min(x) 

Smallest number in dataset x 
mean(x) 

Mean 
median (x) 

Median 
sd(x) 

Standard Deviation 
var(x) 

Variance 
range(x) 

Range 
cor(x, y) 

Correlation 
sum(x) 

Sum of numbers in dataset x 
cumsum(x) 

Cumulative sum of numbers in x 
prod(x) 

Product of numbers in dataset x 
cumprod(x) 

Cumulative product of numbers in x 
diff(x) 

Differences in numbers in dataset x 
summary(x) 

Summary of dataset: minimum, first quartile, median, mean, third quartile, maximum 
fivenum(x) 

Minimum, first quartile, median, third quartile, maximum of dataset 
quantile(x, 0.25) 

Calculates numbers associated with certain percentiles (e.g. 25%) 
IQR(x) 

Interquartile range of x 
weighted.mean(x, w) 

Weighted mean where x is set of values and w is set of weights for each number in x 
rank(x) 

Rank of each number in dataset x 
union(x, y) 

Union of 2 datasets x and y 
intersect(x, y) 

Intersection of 2 datasets x and y 
This work is licensed under a Creative Commons AttributionNonCommercialShareAlike 4.0 International License.