[R] request: most repeated component of a list

Jim Lemon jim at bitwrit.com.au
Fri Sep 12 12:50:33 CEST 2008


Muhammad Azam wrote:
> Thanks for the effort but still we are far from the desired result. May be this example will help you to understand the situation. Example
> a1=c(1:12);   a1=array(a1,dim=c(3,4));   a2=c(1:12);  a2=array(a2,dim=c(3,4));  a3=c(1:16)
> a3=array(a3,dim=c(4,4));  
> a=list(a1,a2,a3); 
> a
> [[1]]
>      [,1] [,2] [,3] [,4]
> [1,]    1    4    7   10
> [2,]    2    5    8   11
> [3,]    3    6    9   12
>
> [[2]]
>      [,1] [,2] [,3] [,4]
> [1,]    1    4    7   10
> [2,]    2    5    8   11
> [3,]    3    6    9   12
>
> [[3]]
>      [,1] [,2] [,3] [,4]
> [1,]    1    5    9   13
> [2,]    2    6   10   14
> [3,]    3    7   11   15
> [4,]    4    8   12   16
>
> Here [[1]] and [[2]] are same out of three (internal values wise). The whole array [[1]] or [[2]] is in majority. So i want to get the whole array or component of list which is in majority. The result should be like this
>      [,1] [,2] [,3] [,4]
> [1,]    1    4    7   10
> [2,]    2    5    8   11
> [3,]    3    6    9   12
>   
Hi Muhammad,
If I have understood the problem, you want to select one or more 
components of a list containing matrices, arrays or data frames that are 
least dissimilar to one or more other components of that list. 
Dissimilarity is defined by the sum of mismatching elements. Because you 
can have more than one set of pairs that are "least dissimilar", the 
attached function returns the indices of the "least dissimilar" pairs 
and the "least dissimilar" components. Hope it does what you want.

Jim


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: find.most.repeated.R
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20080912/d7afb477/attachment.pl>


More information about the R-help mailing list