In: Statistics and Probability
1. Write a code that constructs a matrix with 5 rows that contain the number 1 up to 30. Your output matrix must be filled by the columns.
2. Create the vector_a containing five numeric values 5,7,8,9,10 and vector_b containing five numeric values 2,4,7,9,19. Write the output of the sum of vector_a and vector_b.
3. Create the vector_a containing five numeric values 5,7,8,9,10 and vector_b containing five numeric values 2,4,7,9,19. Write a code that combines vector_a and vector_b.
Ans 1)
Here we have to write a code that constructs a matrix with 5 rows that contain the number 1 up to 30 and output matrix must be filled by the columns.
> m=matrix(1:30,byrow = FALSE,nrow=5) #it gives require matrix > m [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 6 11 16 21 26 [2,] 2 7 12 17 22 27 [3,] 3 8 13 18 23 28 [4,] 4 9 14 19 24 29 [5,] 5 10 15 20 25 30
Ans 2)
> a=c(5,7,8,9,10) > b=c(2,4,7,9,19) > output1=a+b #gives sum of two vector > output1 [1] 7 11 15 18 29
Ans3)
> a=c(5,7,8,9,10) > b=c(2,4,7,9,19) > output2=c(a,b) #it combines the two vector > output2 [1] 5 7 8 9 10 2 4 7 9 19
I have also attached the R code of this question.
m=matrix(1:30,byrow = FALSE,nrow=5) #it gived the matrix of 1:30
fillesd by column
m
a=c(5,7,8,9,10)
b=c(2,4,7,9,19)
output1=a+b #gives sum of two vector
output1
a=c(5,7,8,9,10)
b=c(2,4,7,9,19)
output2=c(a,b) #it combines the two vector
output2