2 Flashcards

1
Q

How to sample a vector in R?

A

sample(y, size, replace, prob=vector), replace = do i want to place the item back in there or leave it out so it cant be selected again.

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

Logical vectors?

A

A vector but with different elements than just numbers, such as booleans

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

Negation in R (true values into false values and vise aversa)?

A

!vector

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

And operator (return a true if both values are true)?

A

vector1 & vector2

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

Or operator (returns a true value if at least one of the values is true)?

A

vector1 | vector2

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

What happens if you take the inequality of two vectors?

A

It returns true or false depending on whether the inequality of those elements hold

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

all(z)?

A

Checks to see if all the elements are true in a logical vector?

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

any(vector)?

A

Return true if at least one of them is true

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

Filter elements using logical vectors?

A

vector[logical vector], filters out all the falses, or, vector[condition such as an inequality]

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

How to do an if else in one line?

A

ifelse(test, output, else)

Example

x = 1, 2, 3, 4, 5, 6, 7, 8

ifelse(x == 8, x, -x): -1, -2, -3, -4, -5, -6, -7, 8

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

Factor function in R?

A

factor(x, level = vector), level is telling the program that there were other possible values, but some of those values are missing from the actual vector.

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

Why is the factor function useful?

A

If you run table(factor(x)), then it counts how many times each value occurs, including the missing values.

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

& operator in R?

A

Compares the logical value of two entire vectors and returns true if the two elements are true.

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

If you have && or || when comparing logical vectors, this means?

A

Scaler; only comparing the first element.

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

Union of two vectors?

A

union(x, y)

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

Intersection of both vectors?

A

intersect(x, y)

17
Q

Removing an element from vector x if it shows up in vector y?

A

setdiff(x, y)

18
Q

Check to see if two vectors are equal?

A

setequal(x, y)

19
Q

Is element f in vector x?

A

“F” %in% x

20
Q

asp?

A

Aspect ratio when a change x in the horizontal axis is the change y in the vertical axis.

21
Q

abline?

A

Plotting lines from a defined number of lines, either v as vertical or h as horizontal

22
Q

removing white borders of plot.new?

A

par(mar = c(x, y, h, z)))

23
Q

How to add axis to a plot?

A

axis(1 or 2 or 3 or 4, at = x:y, levels = x:y, cex.axis = z, pos = j, las = k)

24
Q

Add text to a pre-existing plot?

A

text(x, y, “Text”, pos = h)

25
Q

Adding titles to pre existing plot?

A

title(main = “text”, xlab = “text”, ylab = “text”)

26
Q

add curve to pre existing plot?

A

curve(function, xlim = c(x, y), add = TRUE)

27
Q

Add polygon to pre existing plot?

A

polygon(c(x, y, z, h), c(k, l, a, s)) where a plot is plotted at (x, y) and (y, l)…