[R] The most common row in a matrix?

Adrian DUSA adi at roda.ro
Mon Nov 20 12:45:25 CET 2006


Yet another solution:

library(cluster)
x <- array(1:3,dim=c(4,5))
dissim <- as.matrix(daisy(as.data.frame(x)))
dissim[!upper.tri(dissim)] <- NA
unique(x[which(dissim == 0, arr.ind=TRUE), ])

HTH,
Adrian

On Sunday 19 November 2006 21:31, kone wrote:
> Hi,
>
> How do you get the most common row from a matrix? If I have a matrix
> like this
>
> array(1:3,dim=c(4,5))
>
>       [,1] [,2] [,3] [,4] [,5]
> [1,]    1    2    3    1    2
> [2,]    2    3    1    2    3
> [3,]    3    1    2    3    1
> [4,]    1    2    3    1    2
>
> in which rows 1 and 4 are similar, I want to find that vector c
> (1,2,3,1,2).
>
> Atte Tenkanen
> University of Turku, Finland

-- 
Adrian DUSA
Arhiva Romana de Date Sociale
Bd. Schitu Magureanu nr.1
050025 Bucuresti sectorul 5
Romania
Tel./Fax: +40 21 3126618 \
          +40 21 3120210 / int.101



More information about the R-help mailing list