Example functions

Built-in Named Functions

R has an extensive set of built-in functions, a few of which are listed below:

First six elements/rows:

head()

Last six elements/rows:

tail()

Generate a sequence of values:

seq(from=1, to=10, by=2)
[1] 1 3 5 7 9

Create numbers from string numbers:

as.numeric(c("1","2","3","4"))
[1] 1 2 3 4

Sort a vector alphabetically or numerically:

sort(c(3,4,2,5,1))
[1] 1 2 3 4 5

Retrieve the maximum value from a vector:

max(c(111,333,444,55,6,777,999))
[1] 999

Generate 10 random numbers from a normal distribution with mean 0 and standard deviation 1:

rnorm(10)
 [1]  0.81417493  1.13521137 -0.70086963 -0.07947826 -0.64132781 -1.29416348
 [7]  0.33518589 -0.90487409  0.17206985  0.43583114

For a (very long) list of all named functions available in base-R have a look at this website:

https://stat.ethz.ch/R-manual/R-patched/library/base/html/00Index.html