Convert an Object to List in R Programming – as.list() Function
as.list()
function in R Language is used to convert an object to list. These objects can be Vectors, Matrices, Factors, and data frames.
Syntax: as.list(object)
Parameters:
object: Vector, Matrix, factor, or data frame
Example 1:
# R program to convert object to list # Creating vector x < - c( 1 , 2 , 3 , 4 , 5 ) # Calling as.list() Function as. list (x) |
chevron_right
filter_none
Output:
[[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4 [[5]] [1] 5
Example 2:
# R program to convert object to list # Calling pre-defined data set BOD # Calling as.list() Function as. list (BOD) |
chevron_right
filter_none
Output:
Time demand 1 1 8.3 2 2 10.3 3 3 19.0 4 4 16.0 5 5 15.6 6 7 19.8 $Time [1] 1 2 3 4 5 7 $demand [1] 8.3 10.3 19.0 16.0 15.6 19.8 attr(, "reference") [1] "A1.4, p. 270"