[R] Odp: Request: Most repeated sequence considering combinations at each row

Petr PIKAL petr.pikal at precheza.cz
Mon Oct 27 08:43:27 CET 2008


Hi

not sure if this is what you want. It does not do fuzzy matching but make 
a exact evaluation equal row sums of arrays.

 rle(do.call("c",lapply(lapply(l, rowSums), function(x) paste(x, 
collapse=""))))

Maybe something similar can be done without conversion to character.

Regards
Petr

r-help-bounces at r-project.org napsal dne 24.10.2008 12:34:15:

> Dear friends
> Hope you all are fine. Suppose we have a list of arrays.
> a1=c(4,4,4,4,0,4,4,4,0,3,3,0,0,0,0,0);  a1=array(a1,dim=c(4,4)); 
a2=c(4,4,4,
> 4,0,4,4,4,0,3,3,0,0,0,0,0);  a2=array(a2,dim=c(4,4)); 
> a3=c(4,4,4,4,0,3,3,4,0,4,4,0,0,0,0,0); a3=array(a3,dim=c(4,4)); 
a4=c(4,4,4,4,
> 4,0,3,3,3,3,0,4,4,4,0,0,0,0,0,0); a4=array(a4,dim=c(5,4)); 
a5=c(4,4,4,4,4,0,4,
> 4,4,4,0,3,3,3,0,0,1,1,0,0); a5=array(a5,dim=c(5,4)); 
a6=c(4,4,4,4,4,0,1,1,1,1,
> 0,4,4,4,0,0,3,3,0,0); a6=array(a6,dim=c(5,4)); 
a7=c(1,1,1,1,1,0,4,4,4,4,0,3,3,
> 3,0,0,4,4,0,0); a7=array(a7,dim=c(5,4)); 
a8=c(4,4,4,4,4,0,3,3,3,3,0,1,1,1,0,0,
> 4,4,0,0); a8=array(a8,dim=c(5,4));
> l=list(a1,a2,a3,a4,a5,a6,a7,a8); 
> 
> x <- sapply(1:length(l), function(x) {
>   sum(sapply(l, function(y) {
>     if ( nrow(l[[x]]) != nrow(y) | ncol(l[[x]]) != ncol(y) ) FALSE
>     else sum(y != l[[x]]) == 0
>   }))
> } ); l; x
> 
> Using the above function, we are able to get frequency of each most 
repeated 
> similar components of the list. For example, [[1]] and [[2]] are most 
repeated
> similar out of all. But if we consider the "combinations" at each row of 
each 
> array. Then [[3]] will be included with [[1]] and [[2]]. Also [[5]], 
[[6]] and
> [[8]] will be similar. How can we modify the above function to get the 
desired
> most repeated sequence in this case? Any help in this regard is needed. 
> 
> best regards
> M.Azam 
> 
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list