Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

R Programming: Combine the three vectors to become a 3×3 matrix where each column represents a vector

R Programming: Basic Exercise-12 with Solution

Write a R program to create three vectors a,b,c with 3 integers. Combine the three vectors to become a 3×3 matrix where each column represents a vector. Print the content of the matrix.

Sample Solution :

R Programming Code :

a<-c(1,2,3)
b<-c(4,5,6)
c<-c(7,8,9)
m<-cbind(a,b,c)
print("Content of the said matrix:")
print(m)

Sample Output:

[1] "Content of the said matrix:"
     a b c
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9                         

R Programming Code Editor:



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

Previous: Write a R program to get the unique elements of a given string and unique numbers of vector.
Next: Write a R program to create a list of random numbers in normal distribution and count occurrences of each value.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?