To create a three-dimensional vector in R, you can use the array function.
In this example,
array
function to create a three-dimensional vector.dim
parameter.# Step 1: Create a numeric three-dimensional vector
array_data <- array(data = c(1, 2, 3, 4, 5, 6, 7, 8, 9),
dim = c(3, 3, 3))
# Step 2: Print the vector
print(array_data)
, , 1 [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 , , 2 [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 , , 3 [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9
In this example,
array
function to create a three-dimensional vector.dim
parameter.# Step 1: Create a string three-dimensional vector
array_data <- array(data = c("a", "b", "c", "d", "e", "f", "g", "h", "i"),
dim = c(3, 3, 3))
# Step 2: Print the vector
print(array_data)
, , 1 [,1] [,2] [,3] [1,] "a" "d" "g" [2,] "b" "e" "h" [3,] "c" "f" "i" , , 2 [,1] [,2] [,3] [1,] "a" "d" "g" [2,] "b" "e" "h" [3,] "c" "f" "i" , , 3 [,1] [,2] [,3] [1,] "a" "d" "g" [2,] "b" "e" "h" [3,] "c" "f" "i"
In this tutorial, we learned How to create a Three Dimensional Vector in R language with well detailed examples.