Finding pattern in a matrix in R

前端 未结 7 785
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 04:40

I have a 8 x n matrix, for instance

set.seed(12345)
m <- matrix(sample(1:50, 800, replace=T), ncol=8)
head(m)

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8         


        
7条回答
  •  臣服心动
    2020-12-30 05:22

    Maybe it will help someone, but as for input, I was thinking of the following:

    PatternMatcher <- function(data, ...) {
      Selecting procedure here.
    }
    
    PatternMatcher(m, c(1, 37, 2, 10, 2, 29, 4, 42))
    

    The second part fed to the function consists of, in order, the line where it should start, followed by the value, and then the second line, and the second value. You could now also say for instance the 8th line after the initial line with the value 50.

    You could even extend this to ask for specific X, Y coordinates per value (so 3 items passed to the function per value).

提交回复
热议问题