Rweb in Stat 3011 Home Page Stat 3011 Home Page About the Rweb in Stat 3011 Web Pages
Some of the R language arithmetic operators are
R Operator | Math Operation |
---|---|
+
| addition |
-
| subtraction |
*
| multiplication |
/
| division |
^
| exponentiation |
x <- c(1, 2, 3, 4) x + 2 x^2
Some R functions operate elementwise on vectors.
R Function | Math Function | ||
---|---|---|---|
exp(x)
| ex | ||
log(x)
| (natural) log of x | ||
log10(x)
| common (base 10) log of x | sqrt(x)
| square root |
Other R functions operate on a vector and produce a single number (scalar).
R Function | Math Function |
---|---|
sum(x)
| sum of elements of x
|
prod(x)
| product of elements of x
|
x
is
sum(x^2)
R has a few predefined constants.
R Expression | Math Constant | Definition |
---|---|---|
pi
| 3.14159265... | ratio of circumference and diameter of a circle |
exp(1)
| 2.71828182... | base of natural logarithms |
R has several functions operate on a vector considered as a data set and produce a summary statistic
R Function | Statistics Function |
---|---|
mean(x)
| mean of the data set x
|
mean(x, trim = .10)
| 10% trimmed mean of the data set x
|
median(x)
| median of the data set x
|
var(x)
| sample variance of the data set x
(divides by n - 1 )
|
sd(x)
| sample standard deviation of the data set x ,
same as sqrt(var(x))
|
cor(x, y)
| correlation of the data sets
x and y (which must be the same length).
|
IQR(x)
| interquartile range of the data set x ,
|