0

I have a matrix or data table as below:

which looks like
   time      node1                 node2               node3
   1         100                  200                  300
   2         101                  245                  329   
   3         90                   245                  350 
   4         129                  320                  290
   5         79                   270                  320

I want to read this matrix as:

In first run – 1,101,245,290 and assign to some vector
In second run – 2,90,320,320 and assign to some vector.
In third run—3,129,270 and assign to some vector.

So that in later stage I can use this vector for mathematical calculation.

process is similar to pipeline where every stage gives output per clock tick.

Jaap
  • 81,064
  • 34
  • 182
  • 193
azad
  • 137
  • 1
  • 7

1 Answers1

0

This will get you most of the way there. You can index a data.frame using a matrix. The first column indicates the row and the second the column. It looks like you want to create diagonal vectors

vecs <- lapply(1:3, function(i) df[cbind(pmin(i + 0:3, nrow(df)), 1:4)])

> vecs
[[1]]
[1]   1 101 245 290

[[2]]
[1]   2  90 320 320

[[3]]
[1]   3 129 270 320
Zelazny7
  • 39,946
  • 18
  • 70
  • 84