This is for an R program, so I need help coding this. Vectors, matrices, sequenc
ID: 3271200 • Letter: T
Question
This is for an R program, so I need help coding this.
Vectors, matrices, sequences and logical operators
u = (1, 2, 5, 4) and v = (2, 2, 1, 1)
a) Provide code to define a sequence from 1 to 10 called G and subsequently select the first three components of G.
(b) Define the matrix X whose rows are the u and v vectors from above.
(c) Define the matrix Y whose columns are the u and v vectors from above.
(d) Provide code that sums the rows of the vector Y and report those values.
(e) Consider the vectors u and v from as ordered pairs. Plot the points and colorize each point with a unique color. ( This is part of a question and I have to plot it on a cosine plot with the domain from [-10,10])
Explanation / Answer
## a)
G=seq(1:10)
G
A=G[1:3]
A
## b)
u=c(1,2,5,4)
v=c(2,2,1,1)
X=matrix(c(1,2,2,2,5,1,4,1),2,4)
X
## c)
Y=matrix(c(u,v),4,2)
Y
## d)
sums=rowSums(Y)
sums
OUTPUTS:
## a)
> G=seq(1:10)
> G
[1] 1 2 3 4 5 6 7 8 9 10
> A=G[1:3]
> A
[1] 1 2 3
> ## b)
> u=c(1,2,5,4)
> v=c(2,2,1,1)
> X=matrix(c(1,2,2,2,5,1,4,1),2,4)
> X
[,1] [,2] [,3] [,4]
[1,] 1 2 5 4
[2,] 2 2 1 1
>
> ## c)
> Y=matrix(c(u,v),4,2)
> Y
[,1] [,2]
[1,] 1 2
[2,] 2 2
[3,] 5 1
[4,] 4 1
>
> ## d)
>
> sums=rowSums(Y)
> sums
[1] 3 4 6 5
>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.