Deloitte Interview Questions | What is the function of unlist()?
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 2 )
Unlist function flattens out the list.
Given a list structure x, unlist simplifies it to produce a vector which contains all the
atomic components which occur in x. This function will also unlist all lists within the list as well.
test1 unlist(test1)
[1] “3” “a” “15” “b”
> test2 test2
$v1
[1] 5
$v2
$v2[[1]]
[1] 2983
$v2[[2]]
[1] 1890
$v3
[1] 3 119
> unlist(test2)
v1 v21 v22 v31 v32
5 2983 1890 3 119
unlist function in R, simply converts the list to vector with all the atomic components are being preserved
Syntax for unlist function in R:
unlist(x, recursive = TRUE, use.names = TRUE)