Althe majority of everything in R is done via attributes. Here I"m just refering to numeric and also character functions that are commonly supplied in developing or recoding variables.

(To exercise working with functions, attempt the attributes sections of this this interenergetic course.)

Numeric Functions

Function Description
abs(x) absolute worth
sqrt(x) square root
ceiling(x) ceiling(3.475) is 4
floor(x) floor(3.475) is 3
trunc(x) trunc(5.99) is 5
round(x, digits=n) round(3.475, digits=2) is 3.48
signif(x, digits=n) signif(3.475, digits=2) is 3.5
cos(x), sin(x), tan(x) additionally acos(x), cosh(x), acosh(x), and so on.
log(x) natural logarithm
log10(x) widespread logarithm
exp(x) e^x

Character Functions

Function Description
substr(x, start=n1, stop=n2) Extract or rearea substrings in a character vector. x substr(x, 2, 4) is "bcd" substr(x, 2, 4) continuous expression. If fixed=TRUE then pattern is a text string. Returns equivalent indices. grep("A", c("b","A","c"), fixed=TRUE) retransforms 2
sub(pattern, replacement, x, =FALSE, fixed=FALSE) Find pattern in x and rearea with replacement message. If fixed=FALSE then pattern is a continual expression. If addressed = T then pattern is a text string. sub("\s",".","Hello There") returns "Hello.There"
strsplit(x, split) Split the aspects of character vector x at split. strsplit("abc", "") retransforms 3 aspect vector "a","b","c"
paste(..., sep="") Concatenate strings after using sep string to seperate them. paste("x",1:3,sep="") retransforms c("x1","x2" "x3") paste("x",1:3,sep="M") returns c("xM1","xM2" "xM3") paste("Today is", date())
toupper(x) Uppercase
tolower(x) Lowercase

Statistical Probcapability Functions

The adhering to table describes attributes regarded probaility distributions. For random number generators below, you deserve to use set.seed(1234) or some other integer to develop reproducible pseudo-random numbers.

Function Description
dnorm(x) normal thickness function (by default m=0 sd=1) # plot traditional normal curve x y plot(x, y, type="l", xlab="Typical Deviate", ylab="Density", yaxs="i")
pnorm(q) cumulative normal probcapacity for q (area under the normal curve to the left of q) pnorm(1.96) is 0.975
qnorm(p) normal quantile. worth at the p percentile of normal distribution qnorm(.9) is 1.28 # 90th percentile
rnorm(n, m=0,sd=1) n random normal deviates through suppose m and traditional deviation sd. #50 random normal variates through mean=50, sd=10 x pbinom(q, size, prob) qbinom(p, size, prob) rbinom(n, size, prob) binomial circulation wright here dimension is the sample size and prob is the probcapability of a heads (pi) # prob of 0 to 5 heads of fair coin out of 10 flips dbinom(0:5, 10, .5) # prob of 5 or much less heads of fair coin out of 10 flips pbinom(5, 10, .5)
dpois(x, lamda) ppois(q, lamda) qpois(p, lamda) rpois(n, lamda) poischild circulation through m=std=lamda #probcapacity of 0,1, or 2 events via lamda=4 dpois(0:2, 4) # probcapacity of at least 3 occasions through lamda=4 1- ppois(2,4)
dunif(x, min=0, max=1) punif(q, min=0, max=1) qunif(p, min=0, max=1) runif(n, min=0, max=1) unicreate circulation, adheres to the very same pattern as the normal circulation over. #10 unidevelop random variates x na.rm=FALSE) suppose of object x # trimmed mean, rerelocating any type of missing values and # 5 percent of highest possible and also lowest scores mx # 30th and 8fourth percentiles of x y indices #indices is c(1, 3, 5, 7, 9)
rep(x, ntimes) repeat x n times y # y is c(1, 2, 3, 1, 2, 3)
cut(x, n) divide constant variable in factor with n levels y Robert I.

You are watching: How to square a number in r

See more: Caitlyn Jenner And Bruce Jenner Costume, 10 Results For Bruce Jenner Costume

Kabacoff, Ph.D. | Sitemap