0

For example: I already have my_matrix which is just a simple reactive matrix. I want to extract its rows and assign them to another matrix:

R<-as.matrix(NA)   # create an initial matrix to keep results while looping
for (i in 1:10) { R[i]<-(my_matrix()[i,]) }
Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78

1 Answers1

0

Welcome to stackoverflow. Your question is very sparse on details, which makes it hard to provide a good answer. If you follow the guidance here you should get better answers.

One solution is to create another reactive from the first. For example:

new_matrix = reactive({
    original_matrix = my_matrix()
    R = as.matrix(na)
    for(i in 1:10)
        R[I] = original_matrix[i,]
    return(R)
})

You can then make use of your new matrix by calling new_matrix(), the same way you make use of your original matrix.

Simon.S.A.
  • 6,240
  • 7
  • 22
  • 41
  • brilliant! This is exactly what I was looking for. Thank you so much! – Ilan Livne Oct 17 '18 at 21:29
  • You are welcome. If you find an answer useful it is good practice to up-vote it. If your question has been answered it is good practice to accept a solution. – Simon.S.A. Oct 17 '18 at 22:45