Muhammad Azam
2008-Oct-27 09:32 UTC
[R] Odp: Request: Most repeated sequence considering combinations at each row
Dear Petr Thanks for the response. Hope it will now help me to proceed. best regards M.Azam ________________________________ From: Petr PIKAL <petr.pikal@precheza.cz> Cc: R Help <r-help@r-project.org>; r-help-bounces@r-project.org Sent: Monday, October 27, 2008 8:43:27 AM Subject: Odp: [R] Request: Most repeated sequence considering combinations at each row 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@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 mostrepeated> similar components of the list. For example, [[1]] and [[2]] are mostrepeated> similar out of all. But if we consider the "combinations" at each row ofeach> 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 thedesired> most repeated sequence in this case? Any help in this regard is needed. > > best regards > M.Azam > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
Seemingly Similar Threads
- Request: Most repeated sequence considering combinations at each row
- Fwd: request: most repeated sequnce
- ODP: ODP: Joining BDC (Samba) to PDC (Samba)
- Odp: R: Odp: Function able to identify the row and the column in a matrix
- Odp: Re: Odp: Upgrade 4.2.14 --> 4.3.11