Commands and Functions Flashcards

1
Q

?

A

pull up a help page

Ex: ?seq

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

:

A
colon operator (generate regular sequence)
Ex: 1.5:5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

[ ]

A

subset a vector

Ex: x[c(2, 6, 1, 3)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

[[ ]]

A

extract an element in a list
Ex: x[[“bar”]]
or extract a column in a data frame
Ex: data_frame[[“age”]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

$

A

extract an element in a list
Ex: x$bar
or extract a column in a data frame
data_frame$age

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
A

assignment

Ex: x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

c

A

concatenate

Ex: c(1.1, 9. 3.14)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

seq, seq_along

A

sequence generation

Ex: seq(1, 10, 0.5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

length

A

return the length of a vector

Ex: length(pi:100)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

rep

A

replicate elements of vectors

Ex: rep(c(1, 2, 3), 5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

print

A

prints its argument

Ex: print(5:10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

#

A

comment character

Ex: #ignore the rest of the line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

class

A
return the class of an object
Ex: class(pi)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

as.numeric, as.integer

A

explicit coercion

Ex: as.integer(pi)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

matrix

A

create a matrix

Ex: matrix(1:6, nrow=2, ncol=3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

dim

A

return the dimension attribute of object

Ex: dim(matrix(1:6, nrow=2, ncol=3) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

cbind, rbind

A

create matrix by column-/row- binding vectors

Ex: cbind(1:3, 4:6)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

list

A

create a list

Ex: list(name = “John”, age = 20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

factor

A

create a factor

Ex: factor(“blue”, “green”, levels = c(“red”, “green”, “blue”) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

is.na, is.nan

A

check if the argument is NA (or NaN)

Ex: is.na(as.numeric(“abc”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

data.frame

A

create a data frame

data.frame(foo = 1:4, bar = c(T, T, F, F) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

nrow, ncol

A

return the number of rows/columns of object

Ex: nrow(data.frame(foo = 1:4, bar = c(T, T, F, F) ) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

names

A

names of elements of a vector

Ex: names(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

colnames, rownames

A

column/row names of a matrix/data frame

Ex: colnames(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

paste

A

concatenate strings

Ex: paste(“aa”, “bb”, “cc”, sep = “:”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

sum

A

summation of elements in a vector

Ex: sum(c(1, 5, 12) )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

prod

A

product of elements in a vector

Ex: prod(c(3, 15, -2) )

28
Q

max, min

A

maximum/minimum value in a vector

Ex: max(c(23, 12, 12, 3) )

29
Q

mean, median

A

mean/median of a vector

Ex: mean(c(1, 5, 1, 2, 7) )

30
Q

sort

A

sorting

Ex: sort(c(1, 5, 1, pi, 2, 7) )

31
Q

var, sd

A

sample variance/standard deviation of a vector

Ex: sd(c(1, 5, 1, 3, 2) )

32
Q

cor

A

correlation

Ex: cor(c(1, 4, 6, 1), c(2, 5, 1, 9) )

33
Q

which.min, which.max

A

first index of minimum/maximum value

Ex: which.min(c(4, 1, 3, 4, 1) )

34
Q

set.seed

A

set a seed for random number generation

Ex: set.seed(13218)

35
Q

> ,

A

greater/less than

Ex: 1:5 > seq(0, 8, 2)

36
Q

==

A

equality operator

Ex: 1:5 == seq(0, 8, 2)

37
Q

> =, <=

A

greater or equal to/less than or equal to

Ex: 1:5 <= seq(0, 8, 2)

38
Q

!=

A

not equal to

Ex: 1:5 != seq(0, 8, 2)

39
Q

!

A

NOT

Ex: !(1 > 2)

40
Q

&

A

AND

Ex: (3:5 > 5:7) & (4:6 == 4:6)

41
Q

|

A

OR

Ex: (3:5 > 5:7) | (4:6 == seq(2, 6, 2) )

42
Q

abs

A

absolute value

Ex: abs(3 - 6) = 3

43
Q

sqrt

A

square root

Ex: sqrt(16) = 4

44
Q
A

exponentiation

Ex: 3^10 = 59049

45
Q

exp

A

exponential function

Ex: exp(1.7) = e^1.7 = 5.473947

46
Q

log

A
log function (base e)
Ex: log(10) = 2.302585
47
Q

log10

A

base 10 log (log sub 10)

Ex: log10(100) = 2

48
Q

pi

A

mathematical constant π

Ex: pi = 3.141593

49
Q

sin, cos, tan

A
trigonometric functions (argument in radians)
Ex: sin(pi/2) = 1
50
Q

asin, acos, atan

A

inverse trigonometric functions

Ex: acos(1) = 0

51
Q

sinh, cosh, tanh

A

hyperbolic functions

Ex: cosh(0) = 1

52
Q

asinh, acosh, atanh

A

inverse hyperbolic functions

Ex: atanh(tanh(12)) = 12

53
Q

round(x, n)

A

round x to n decimal places

Ex: round(pi, 2) = 3.14

54
Q

floor

A

rounds down

Ex: floor(14.7) = 14

55
Q

ceiling

A

rounds up

Ex: ceiling(14.7) = 15

56
Q

dnorm, pnorm, qnorm, rnorm

A
Normal Distribution
[p for “probability”, the cumulative distribution function (cdf)
q for “quantile”, the inverse cdf
d for “density”, the probability density function (pdf)
r for “random”, a random variable having the specified distribution]
Ex: dnorm(-3:3)
curve(dnorm(x), xlim=c(-3,3))
pnorm(1.65)
pnorm(-1.65)
qnorm(0.05,lower.tail=FALSE)
set.seed(107281)
rnorm(10)
57
Q

dchisq, pchisq, qchisq, rchisq

A

χ^2 (Chi-Squared) Distribution
[p for “probability”, the cumulative distribution function (cdf)
q for “quantile”, the inverse cdf
d for “density”, the probability density function (pdf)
r for “random”, a random variable having the specified distribution]
Ex: curve(dchisq(x,1),xlim=c(0,15),ylim=c(0,0.6),ylab=”Chi Square Density”)
pchisq(21.78,10,lower.tail=FALSE)
qchisq(0.05,10,lower.tail=FALSE)

58
Q

dt, pt, qt, rt

A

Student t Distribution
[p for “probability”, the cumulative distribution function (cdf)
q for “quantile”, the inverse cdf
d for “density”, the probability density function (pdf)
r for “random”, a random variable having the specified distribution]
Ex: curve(dt(x,1),xlim=c(-5,5),ylim=c(0,0.4),ylab=”Student’s t Density”)

59
Q

read.table, read.csv

A

read data from a text file

Ex: data

60
Q

write.table, write.csv

A

write data to a text file

Ex: write.csv(data, “foo.csv”)

61
Q

readLines

A

read text file line by line

Ex: data

62
Q

writeLines

A

write text to file

Ex: writeLines(“write something…”, “foo.txt”)

63
Q

hist

A

plot a histogram

Ex: hist(rnorm(1e5), freq = FALSE, breaks = 100)

64
Q

curve

A

plot a function

Ex: curve(x^2, xlim = x(-1, 1) )

65
Q

legend

A

add a legend to a plot

Ex: legend(1, 2, c(“text1”, “text2”), col = 1:2, lty=1:2)