Data Frames Flashcards

1
Q

What is a data frame?

A

Two dimensional object

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

Can a single data frame hold elements of multiple data types?

A

Yes

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

Which functions show the first or last observations in the dataset?

A

head() and tail()

Ex: head(my_df)

Ex: tail(my_df)

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

Which function gives an overview of the data in your dataset?

A

str()

Ex: str(my_df)

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

What does the str() function reveal?

A

The total number of observations (e.g. 32 car types)

The total number of variables (e.g. 11 car features)

A full list of the variables names (e.g. mpg, cyl … )

The data type of each variable (e.g. num)

The first observations

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

What is the function to create a data frame?

A

data.frame()

Ex: data.frame(my_vec1, my_vec2, my_vec3, …)

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

How can you select a single element from a data frame?

A

[num1, num2]

Ex: my_df[1,2]

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

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

A

[num1:num2, num3:num4] OR [num1:num2, var]

Ex: my_df[1:3, 2:4] OR my_df[1:3, “type”]

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

How can you select an entire column or row from a data frame?

A

[,num] and [num,] and $var

Ex: my_df[,1]

Ex: my_df[1,]

Ex: my_df$type

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

Which function selects a portion of the data frame based on whether or not a certain condition is true?

A

subset()

Ex: subset(my_df, subset = some_condition)

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

Which function sorts the data according to a certain variable in the dataset?

A

order()

Ex: order(c(100, 10, 1000)) will print 2, 1, 3

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

How can we use the output of order(a) to reshuffle a?

A

a[order(a)] will print out a in order

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