To create a two-dimensional vector in R, you can use the list
function to create a list of vectors.
In this example,
list
function to create a list containing numeric vectors as its elements.# Step 1: Create a numeric two-dimensional vector
matrix <- list(c(1, 2, 3), c(4, 5, 6), c(7, 8, 9))
# Step 2: Print the two-dimensional vector
print(matrix)
[[1]] [1] 1 2 3 [[2]] [1] 4 5 6 [[3]] [1] 7 8 9
In this example,
list
function to create a list containing character vectors as its elements.# Step 1: Create a character two-dimensional vector
matrix <- list(c("a", "b", "c"), c("d", "e", "f"), c("g", "h", "i"))
# Step 2: Print the two-dimensional vector
print(matrix)
[[1]] [1] "a" "b" "c" [[2]] [1] "d" "e" "f" [[3]] [1] "g" "h" "i"
In this tutorial, we learned How to create a Two Dimensional Vector in R language with well detailed examples.