0% found this document useful (0 votes)
7 views1 page

R Calculator Functions and Commands

R can be used as a calculator to perform arithmetic operations like addition, subtraction, multiplication, division, and exponentiation on scalars. It also contains functions for common calculations like logarithms, trigonometry, square roots, and statistical distributions. Help is available through the ? and ?? commands, variables can be assigned and printed, and files and directories can be managed within the R environment.

Uploaded by

keyojeli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

R Calculator Functions and Commands

R can be used as a calculator to perform arithmetic operations like addition, subtraction, multiplication, division, and exponentiation on scalars. It also contains functions for common calculations like logarithms, trigonometry, square roots, and statistical distributions. Help is available through the ? and ?? commands, variables can be assigned and printed, and files and directories can be managed within the R environment.

Uploaded by

keyojeli
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

R as a Calculator (for Scalars)

Command Meaning Example


Arithmetic:
x [+-*/^] y x + y, x y, xy, x/y, xy 7 / 3, 8^(1/3)
x %/% y integer division 7 %/% 3
x %% y modulo (remainder) 7 %% 3
Calculator functions:
exp() exponential exp(1)
log(x, base = exp(1)) logarithm log(9, base = 3)
(= indicates default) e = exp(1); log(e^2)
cos(), sin(), tan() trigonometry sin(pi/2)
sqrt() square root sqrt(9)
Other easy functions:
abs(x) absolute value abs(-3)
floor(x) greatest int x floor(-1.5)
ceiling(x) smallest int x ceiling(-1.5)
round(x, digits = 0) round to #decimal places round(4/3, 2)
signif(x, digits = 6) round to #significant signif(4/3, 2)
Statistics distributions:
dnorm(x, mean = 0, sd = 1) f (x) dnorm(0) # density
pnorm(q, mean = 0, sd = 1) P (X q) for X N (mean, sd) pnorm(-1, 0, 1) # probability
qnorm(p, mean = 0, sd = 1) x with P (X x) = p qnorm(.16, 0, 1) # quantile
rnorm(n, mean = 0, sd = 1) random from N (0, 1) rnorm(1, 7, .01) # random
[dpqr][t,chisq,f,binom]() other distributions ?pt, pt(-2, 100)
Miscellaneous:
?pt (help includes Description, Usage,
?name help("name")
Arguments, Value, Examples)
??topic [Link]("topic") ??deviation
<- (or =) assign variable x <- 3 (or x = 3)
[Link] print([Link]) x
ls() list variables
rm(list = ls()) clear all variables
[Link]() list all files
# comment rest of line N <- 3 # number of points
quit() quit R
source(file) read code from file source("quiz1.R")
setwd(dir) set working directory setwd("/Users/jgillett/Desktop/327")
Shortcuts Help > Keyboard Shortcuts
...
, (up-, down-arrow) previous command, next
Esc interrupt current command
...

You might also like