Dear R community
The following code gives me the most repeated sequence of values. i.e.
x=c(1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,2,3,3,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3,3,3,4,4,4,0,0,0,0,0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,
 0,0,0,0,0,0,1,2,2,2,2,2,0,3,3,0,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
  x=array(x,dim=c(3,6,7))
  apply(x,3,function(.mat){

    rows <- table(apply(.mat,1,function(z){
        # remove the zeros
        z <- z[z != 0]

        paste(z,collapse=' ')
    }))
    # remove empty strings
    rows <- rows[names(rows) != ""]

    if (!is.null(rows)){
        return(names(rows)[which.max(rows)])    # return(table(names(rows)))
    } else return(NULL)
  })

I am trying to get frequencies of all the sequences instead of most repeated using  "return(table(names(rows)))". But i could not get the desired results (i mean frequencies of all possible sequences)e.g. for first sector the result should be
1    
3    
and so on. Please suggest me some suitable way. Thanks 


Muhammad Azam


      
	[[alternative HTML version deleted]]

