To create a Two-Dimensional List in R, you can use nested lists or the matrix function to initialize the elements.
In this example,
matrix
to represent the 2D list.matrix <- list(
list(1, 2, 3),
list(4, 5, 6),
list(7, 8, 9)
)
print(matrix)
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
In this example,
matrix
to represent the 2D list.matrix <- matrix(
c('a', 'b', 'c', 'd', 'e', 'f'),
nrow = 2,
byrow = TRUE,
dimnames = list(c('row1', 'row2'), c('col1', 'col2', 'col3'))
)
print(matrix)
col1 col2 col3 row1 'a' 'b' 'c' row2 'd' 'e' 'f'
In this tutorial, we learned How to create a Two Dimensional List in R language with well detailed examples.