Recall & Review
beginner
What is a data frame in R?
A data frame is a table-like structure in R that holds data in rows and columns. Each column can have different types like numbers, text, or factors.
Click to reveal answer
beginner
How do you create a simple data frame with columns 'Name' and 'Age' in R?
Use the
data.frame() function like this:<br>data.frame(Name = c("Alice", "Bob"), Age = c(25, 30))Click to reveal answer
beginner
What happens if columns in a data frame have different lengths?
R will give an error because all columns in a data frame must have the same number of rows.
Click to reveal answer
beginner
How can you check the structure of a data frame after creating it?
Use the
str() function to see the structure, types, and sample data of the data frame.Click to reveal answer
beginner
Can a data frame column contain different data types?
No, each column must have the same data type, but different columns can have different types.
Click to reveal answer
Which function is used to create a data frame in R?
✗ Incorrect
The correct function to create a data frame in R is
data.frame().What will happen if you try to create a data frame with columns of unequal length?
✗ Incorrect
R requires all columns in a data frame to have the same length; otherwise, it throws an error.
Which of these is a valid way to create a data frame with two columns 'x' and 'y'?
✗ Incorrect
Only option D has columns of equal length (3), which is required for data frames.
How do you view the structure of a data frame named df?
✗ Incorrect
The
str() function shows the structure of the data frame including types and sample data.Can a single column in a data frame contain both numbers and text?
✗ Incorrect
Each column in a data frame must have the same data type for all its values.
Explain how to create a data frame in R with three columns: Name, Age, and City.
Think about how you combine vectors into a table.
You got /3 concepts.
Describe what happens if you try to create a data frame with columns of different lengths.
Imagine a table where rows must line up.
You got /3 concepts.