R Introduction Flashcards

1
Q

scalar, vector, matrix, array, list, data.frame

A

• scalar: variable with just one value
• vector: variable with several values of the same type
• Array: multidimensional collection of objects of the
same type (numbers or characters or factors)
• Matrix: special two dimensional array, as it is so often used, it has it’s own command
• Lists: ordered collections of objects not necessarily
of the same type (Access with rectangular brackets or $ notation)
• Data frame: a list of vectors
(Different vectors of one data.frame can have
different types; access for data frame columns also with $ or with brackets [])

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

mtr[1,1], mtr[1:10,], mt[,’col’],df$col, df$col[4], vec[4]

A

matrices:
mtr[1,2]: element 1, column 2
mtr[1:10,]: first 10 elements in every column (?)
mt[,’col’]: column named “col”
dataframes:
df$col same as df[[“col”]]: Column named “col”
df$col[4]: Column named “col” 4th element
vector:
vec[4]: 4th element

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

sorting, aggregating: sort, rev, order, aggregate, apply

A
sorting: gives back values
rev:
order: gives back indices
aggregate: Aggregate: apply a function for a vector against each level of a categorical variable; zusammenfassung der Daten ohne Summary zu nutzen (ausgewählte Daten ) 
apply:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

R data structures

A
name (dimension, type)
scalar (0,1)
vector (1,1)
Array (>=2,1)
Matrix (2,1)
List (1,>=1)
Data-Frame (2, >=1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

data reading: data, read.table, load, source

A

data: load certain dataset > data(HairEyeColor)
read.table: loading from FLAT Files (library(base), read.table)
load: • You can explicitly load and save your session with
save.image, save <> load
savehistory <> loadhistory

source: load the file inside R or execute the file from the
terminal source('/path/to/sample.r')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

daten manipulation, structuring: data.frame, matrix, cbind, rbind,
colnames, rownames, merge

A

data.frame: Data frame: a list of vectors, Different vectors of one data.frame can have
different types, access for data frame columns also with $ or with brackets []
matrix: x[,c(1,3)] = colum 1 and 3

cbind
rbind,
colnames
rownames
merge
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

control flow: if, else if, else; for, while

A

• decisions: if (if cond1 is TRUE do something …), else if (if cond2 is TRUE do something …), else (neither cond1 or cond2 are true do something else …)
• loops: for, while
• loop control: break, next
–> keywords

for (i in vec) {
# do something
}
while (cond) {
# do something
}
repeat {
if (cond) { break }
# do something
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Basic operators

A
  • Mathematical: *, /, +, -, , ==, …
  • Logical: & (and), | (or), %in% (in) , ! (not)…
  • Own: ’%ni%’ FALSE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

functions and their arguments: default, optional, special “…”, return

A

Arguments
• mandatory: without = sign
• optional: with = sign and default value
The magic ...” Argument
take any argument and delegate it my.barplot: light blue barplot always with a box around

Return in Functions
• need values outside function: use return
• just perform some sequence of operations no return
• R implicitly always returns the last statement

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