Data Frames Flashcards
What is a data frame?
Two dimensional object
Can a single data frame hold elements of multiple data types?
Yes
Which functions show the first or last observations in the dataset?
head() and tail()
Ex: head(my_df)
Ex: tail(my_df)
Which function gives an overview of the data in your dataset?
str()
Ex: str(my_df)
What does the str() function reveal?
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
What is the function to create a data frame?
data.frame()
Ex: data.frame(my_vec1, my_vec2, my_vec3, …)
How can you select a single element from a data frame?
[num1, num2]
Ex: my_df[1,2]
How can you select multiple in-sequence elements from a data frame?
[num1:num2, num3:num4] OR [num1:num2, var]
Ex: my_df[1:3, 2:4] OR my_df[1:3, “type”]
How can you select an entire column or row from a data frame?
[,num] and [num,] and $var
Ex: my_df[,1]
Ex: my_df[1,]
Ex: my_df$type
Which function selects a portion of the data frame based on whether or not a certain condition is true?
subset()
Ex: subset(my_df, subset = some_condition)
Which function sorts the data according to a certain variable in the dataset?
order()
Ex: order(c(100, 10, 1000)) will print 2, 1, 3
How can we use the output of order(a) to reshuffle a?
a[order(a)] will print out a in order