Chapter 1 - Introduction to R Flashcards

Memorize common functions

1
Q

Exponential/Log functions

A

exp(…) and log(x, base)

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

Install a package and load

A

install.packages(‘…’), library(package)

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

Scatter plot

A

plot(X,Y)

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

Histogram

A

hist(X)

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

Make a vector

A

x <- c(…)

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

Sum, Mean, Standard dev, length of a vector?

A

sum(), mean(), sd(), length()

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

Multiple plots at once? 1 row 2 col? 2 row 1 col?

A

par(mfrow = c(1,2)) and par(mfrow = c(2,1))

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

Make lines in a plot

A

lines(X,Y)

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

What order does R upcast to for vectors?

A

Boolean -> Numeric -> String

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

Check object types for numeric, factor, logical, and character.

A

as.”type”

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

Print a string without quotations.

A

cat(…)

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

Count the number of characters in a string.

A

nchar(a)

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

Character translation function

A

chartr(old, new, string)

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

Make a string upper case, lower case?

A

toupper(a), tolower(a)

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

Get a sub-string.

A

substr(beg,end,string)

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

Paste function

A

paste(a,b,sep = “”, collapse = “”)

17
Q

Split a string

A

strsplit(a, split = “”)

18
Q

Combine two vectors into one

A

c(a,b)

19
Q

Make columns in a regular vector

A

c(‘name’ = c(…))

20
Q

Make a sequence of numbers in R

A

seq(start,end,step) or a:b (for integers)

21
Q

Repeat a vector

A

rep(x, integer for repeating the whole vector)
rep(x, vector for times of each item)
rep(x, each = a)

22
Q

Make a matrix

A

x <- c(…); dim(x) <- c(row,col)
or
matrix(x,nrow, ncol, byrow, bycol)

23
Q

Adjust the dimension names of a matrix.

A

rownames(x) <- c(…)
colnames(x) <- c(…)
names(dimnames(x)) <- c(…)

24
Q

Combine columns and rows for two vecotrs/matrix

A

Example
cbind(A = 1:3, B = 4:6, C = 7:9)
rbind(A = 1:4, B = 4:6, C = 7:9)

25
Q

Factors/Categorical Data in R

A

factor(data, levels = c(…))
or
factor(data); levels(data) <- c(…)

26
Q

Make a list

A

mylist <- list(before = intake.pre, after = intake.post)

27
Q

Index a list, with conditions?

A

mylist$column
mylist$column[index]
mylist$column[condition]

28
Q

Index a vector, with conditions?

A

x[condition]
x[index]

29
Q

Make a dataframe

A

data <- data.frame(col1,col2,…)

30
Q

Index a data frame, with conditions?

A

data[row,col]

Generally with conditioning data frames it looks like this, can be changed.
row cond col cond
data[data$col ==|%<>, c(…)]

31
Q

Check if a vector/item is inside another vector?

A

%in%