Skip to content
Prev 155269 / 398506 Next

request: most repeated sequnce

---------- Forwarded message ----------
From: jim holtman <jholtman at gmail.com>
Date: Sun, Sep 7, 2008 at 11:42 AM
Subject: Re: [R] request: most repeated sequnce
To: Muhammad Azam <mazam72 at yahoo.com>


This should do it for you:
+ 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)
+
+     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)])
+     } else return(NULL)
+  })
[[1]]
[1] "1"

[[2]]
[1] "1 2 3"

[[3]]
[1] "1 2 3 4"

[[4]]
[1] "1 2 3 4"

[[5]]
[1] "2 2 3 4"

[[6]]
character(0)

[[7]]
[1] "1"

        
On Sun, Sep 7, 2008 at 8:08 AM, Muhammad Azam <mazam72 at yahoo.com> wrote:
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?
Message-ID: <644e1f320809070843g1d615cfh30ddbf2c223699e1@mail.gmail.com>
In-Reply-To: <644e1f320809070842x74067293ve599a6fe6c9db868@mail.gmail.com>