manuel459
manuel459

Reputation: 193

Writing a vector into a matrix

let's say i got x=seq(0,1,0.2) and y=x[1:2]. How do I say that a given matrixes, e.g. z=matrix(0,10,10), first 2 inputs in the first column should be the ones from y?. So I want to be y a part of z (if that makes sense).

I tried z[[1:2],1]=y but this doesn't work.

How do I do that neatly without any loops?

Thank you!

Upvotes: 1

Views: 75

Answers (2)

ThomasIsCoding
ThomasIsCoding

Reputation: 101373

Since the length of y is less than the number of rows of z, you can use

z[1:2] <- y

since values are assigned by columns from left to right

Upvotes: 1

akrun
akrun

Reputation: 887118

We don't need the double brackets

z[1:2, 1] <- y

Upvotes: 1

Related Questions