Vectors Flashcards

1
Q

What is a vector?

A

One dimensional array

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

Can a single vector hold elements of multiple data types?

A

No

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

What is the function to create a vector?

A

c()

Ex: c(“a”, “b”, “c”)

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

What is the function to name elements of a vector?

A

names()

Ex: names(my_vector) <- c(“name1”, “name2”)

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

What happens when two vectors are added, subtracted, etc.?

Ex: c(1, 2, 3) + c(4, 5, 6)

A

The result is calculated element-wise.

Ex Result: 5, 7, 9 is printed

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

Which function sums all elements in a vector?

A

sum()

Ex: sum(my_vector)

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

What index do vectors in R start at?

A

1

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

How can you select a single element from a vector?

A

[num]

Ex: my_vector[2] OR my_vector[“Monday”]

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

How can you select multiple out-of-sequence elements from a vector?

A

[c()]

Ex: my_vector[c(1, 5)] OR my_vector[c(“Monday”, “Wednesday”)] OR my_vector[c(TRUE, FALSE, TRUE)]

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

How can you select multiple in-sequence elements from a vector?

A

[num1:num2]

Ex: my_vector[2:5]

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

What happens when a vector is compared to a single object?

Ex: c(1, 3, 5) > 4

A

Each element in the vector is compared to the object.

Ex Result: FALSE FALSE TRUE is printed

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