I have
diag(1:3)
# [,1] [,2] [,3]
# [1,] 1 0 0
# [2,] 0 2 0
# [3,] 0 0 3
and I need
matrix(data=c(0,1,0,0,2,0,0,0,3),nrow=3,ncol=3)
# [,1] [,2] [,3]
# [1,] 0 0 0
# [2,] 1 2 0
# [3,] 0 0 3
And I have to repeat this operation several times on a huge dataset.
Basically I need to move one observation from one line (3 in my dataset) below.
From what I know about R, I think I should find a condition and store it in a loop to run it on my huge dataset. I also thought about using the apply
function but I do not know how.
I am very new on R, thus I want to apologize if my question sounds bad,or if it has already been ask and I want to thanks the R community for their knowledge.