0
0
R Programmingprogramming~5 mins

Data frame creation in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Adata.frame()
Bcreate.df()
Cmake.data()
Dframe.create()
What will happen if you try to create a data frame with columns of unequal length?
AR will throw an error
BR will fill missing values with zeros
CR will recycle shorter columns automatically
DR will create a list instead
Which of these is a valid way to create a data frame with two columns 'x' and 'y'?
Adata.frame(x = c(1,2), y = c('a','b','c'))
Bdata.frame(x = 1:3, y = c('a', 'b'))
Cdata.frame(x = 1:3, y = c('a', 'b', 'c'))
Ddata.frame(x = 1:3, y = 1:2)
How do you view the structure of a data frame named df?
Ahead(df)
Bview(df)
Csummary(df)
Dstr(df)
Can a single column in a data frame contain both numbers and text?
AYes, columns can mix types freely
BNo, each column must have one data type
COnly if you convert the column to a list
DOnly if you use factors
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.