Search code examples
matrixpositionmodulo

Quotient in R to hold position in a matrix


Let's assume these are our numbers and we are looking for mod for them which we can find them using library(pracma)

> mod(c(1,4,23,13,8,9,11,27,32,2),7) 
> [1] 1 4 2 6 1 2 4 6 4 2

I want to get a number to see where each number is coming from when it is a matrix?

1,1,4,2,2,2,2,4,5,1

For example; if this is an m by 7 matrix; We know that it is on 2nd column but what row? 9 is 2nd row (2,2) but not quotient is 1, then 23 is 4th row (4,2) but quotient is 3. Finally, last element 2 is on (1,2).

I am looking for row position since I can use the mod as a column position.


Solution

  • I came out with this

    b=c(1,4,23,13,7,9,11,27,32,2)
    floor(b/7+1)
    [1] 1 1 4 2 2 2 2 4 5 1