1/33
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
FRONT
BACK
FIRST PASS
FIRST PASS
SECOND PASS
SECOND PASS
What are the arguments for data frames and what do they do?
Data frames have six arguments:
The data
row.names
check.rows: Fixes rare instances where rows can have inconsistent lengths or faulty names without producing an error
check.names: Corrects column names if they are incompatible or duplicates
fix.empty.names: Gives columns with no names a name
stringsAsFactors: Whether to autoconvert character vectors to factors
How do you change the levels of a factor?
levels(factor) <- c(x)
What are the arguments for factors and what do they do?
There are 6 arguments:
x - the data
levels - buckets to match the data to
labels - relabels the buckets from the data names
exclude - what data you want to exclude, (makes them NA)
ordered - (whether or not the levels are hierarchical)
nmax - (maximum number of levels)
What’s the difference between the str() and summary() function?
str() tells you about what’s inside the object, summary() gives you statistical information about the object
What are the two ways you can select list elements other than through numbers?
There are two ways. First through double brackets with the label. Second with a dollar sign.
Ex1: list[[“label”]]
Ex2: list$label
What function allows you to select rows from a dataframe that meet a specific column condition? What are its arguments?
subset(dataframe, condition)
What is a factor?
A statistical data type used to store categorical variables
How do you create a factor?
x <- factor(vector)
How do you get the levels of a factor?
levels(factor)
How are factor levels automatically ordered if you don’t specify them?
Alphabetically
What function gives you a statistical overview of the contents of an object/variable?
summary()
What happens if you try to compare unordered factors?
You get a warning
Are factors unordered or ordered by default?
Unordered
Do factors order from least to greatest, or greatest to least?
Least to greatest
How do you access a specific cell from a factor?
factor[x]
What is the function to create a data frame?
data.frame()
What is the main difference between a matrix and a data frame?
Data frames can contain many different types of data at the same time, where matrices only contain data of the same type
What functions print the first 6 and last 6 lines of data from a data frame or matrix?
head() and tail()
What function shows you the structure of an object?
str()
Can data frames have identical row names?
Not usually
What is a good way to remember how you select data frame elements?
Same as matrix selection
Are there any ways you can select data frame elements other than through numbers? If so, provide an example.
Yes, you can select them through the labels of the rows or columns.
Ex: matrix[1, “label”]
How can you select all of the elements of a column in a dataframe without using brackets?
dataframe$columnname
What happens if you pass a boolean vector as one of the bracket arguments of a dataframe?
You return a dataframe with only the elements in that row or column that are true
What function sorts data from least to greatest?
order()
What function is like a vector, but can carry different variable types?
list()
How do you name a list’s rows while initializing them?
list(name1 = x, name2 = y)
Can you name vectors?
Yes
What’s the difference between single brackets and double brackets for lists?
The single bracket returns the container (a list), the double bracket returns the actual element inside the container
How do you select a specific element FROM a specific element, from a list?
list[[x]][y]
Why don’t dataframes have an argument for the column names?
The labels of the data used to create the dataframe become the column names automatically