Finding duplicate values in r

前端 未结 3 674
萌比男神i
萌比男神i 2021-01-23 06:32

So, In a string containing multiple 1\'s,

Now, it is possible that, the number

\'1\' 

appears at several positions, let\'s say, at m

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 06:42

    Perhaps the following route will help:

    1. Convert string to a vector of integers characters

      v <- as.integer(strsplit(s, "")[[1]])
      
    2. Repeatedly convert this vector to matrices of varying number of rows...

      m <- matrix(v, nrow=...)
      
    3. ...and use rle to find relevant patterns in the rows of the matrix m:

      rle(m[1, ]); rle(m[2, ]); ...
      

提交回复
热议问题