0
0
R Programmingprogramming~5 mins

List to vector conversion in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a list in R?
A list in R is a collection that can hold elements of different types and sizes, like numbers, strings, or even other lists.
Click to reveal answer
beginner
What is a vector in R?
A vector in R is a sequence of elements of the same type, like all numbers or all characters, stored in a single structure.
Click to reveal answer
beginner
How do you convert a list to a vector in R?
You can use the function unlist() to flatten a list into a vector by combining all elements into one sequence.
Click to reveal answer
intermediate
What happens if the list contains elements of different types when using unlist()?
R will coerce all elements to a common type, usually converting everything to character if types differ, to create a single vector.
Click to reveal answer
beginner
Write the R code to convert the list my_list <- list(1, 2, 3) to a vector.
Use my_vector <- unlist(my_list). This will create a numeric vector c(1, 2, 3).
Click to reveal answer
Which R function converts a list to a vector?
Aunlist()
Bas.vector()
Clist()
Dc()
What type of elements does a vector in R contain?
AOnly lists
BElements of the same type
COnly numbers
DElements of different types
If a list contains numbers and characters, what will unlist() produce?
AA character vector
BA numeric vector
CA list
DAn error
What does the following code return? unlist(list(1, 2, 3))
AA character vector
BA list with elements 1, 2, 3
CA numeric vector c(1, 2, 3)
DNULL
Which of these is NOT true about unlist()?
AIt can convert nested lists to vectors
BIt returns a vector
CIt coerces elements to a common type
DIt preserves the original list structure
Explain how to convert a list to a vector in R and what happens if the list has mixed types.
Think about how R handles different data types when combining.
You got /4 concepts.
    Describe the difference between a list and a vector in R with examples.
    Consider how you store different items in a shopping bag vs. a row of identical boxes.
    You got /4 concepts.