Q:

Write a R program to create a matrix from a list of given vectors

0

Write a R program to create a matrix from a list of given vectors.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

l = list()
for (i in 1:5) l[[i]] <- c(i, 1:4)
print("List of vectors:")
print(l)
result = do.call(rbind, l)
print("New Matrix:")
print(result)

Sample Output:

[1] "List of vectors:"
[[1]]
[1] 1 1 2 3 4

[[2]]
[1] 2 1 2 3 4

[[3]]
[1] 3 1 2 3 4

[[4]]
[1] 4 1 2 3 4

[[5]]
[1] 5 1 2 3 4

[1] "New Matrix:"
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    2    3    4
[2,]    2    1    2    3    4
[3,]    3    1    2    3    4
[4,]    4    1    2    3    4
[5,]    5    1    2    3    4

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now