w3resource

R Programming: Create an array with three columns, three rows, and two 'tables', taking two vectors as input to the array

R Programming: Basic Exercise-18 with Solution

Write a R program to create an array with three columns, three rows, and two "tables", taking two vectors as input to the array. Print the array.

Sample Solution :

R Programming Code :

v1 = c(1, 3, 5, 7)
v2 = c(2, 4, 6, 8, 10)
arra1 = array(c(v1, v2),dim = c(3,3,2))
print(arra1)

Sample Output:

, , 1

     [,1] [,2] [,3]
[1,]    1    7    6
[2,]    3    2    8
[3,]    5    4   10

, , 2

     [,1] [,2] [,3]
[1,]    1    7    6
[2,]    3    2    8
[3,]    5    4   10                         

R Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a R program to create an array, passing in a vector of values and a vector of dimensions. Also provide names for each dimension.
Next: Write a R program to create a list of elements using vectors, matrices and a functions. Print the content of the list.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.