Thanks a lot. This was very helpful. I want to apologise for being
unprecise. My favourite solution was William's.
Thanks again.
2015-10-07 18:39 GMT+02:00 William Dunlap :
> You could also call table() on the columns of the input matrix, first
> converting them
> to factors with levels 1:max. T
rtment of Anthropology
Texas A&M University
College Station, TX 77840-4352
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Hermann Norpois
Sent: Wednesday, October 7, 2015 12:17 AM
To: Boris Steipe; r-help
Subject: Re: [R] Measure the frequencies of
Ok, this was misleading. And was not that important. My result matrix
should look like this:
12 3 4 5 6 7 ...
1 p1 p2
2 p
3
4
p1 etc are the frequencies of the combinations
1 and 2 for instance do not appear in my example. So the values would be
zero. Actually, this part is not t
You could also call table() on the columns of the input matrix, first
converting them
to factors with levels 1:max. Then add together the upper and lower
triangles of
the table if order is not important. E.g.,
f2 <- function (mat)
{
maxMat <- max(mat)
stopifnot(is.matrix(mat), all(mat %in
lf Of Boris Steipe
Sent: Wednesday, October 7, 2015 8:10 AM
To: Hermann Norpois
Cc: r-help
Subject: Re: [R] Measure the frequencies of pairs in a matrix
Still not sure I understand. But here is what I think you might mean:
# Your data
mat <- structure(c(5, 6, 5, 5, 4, 3, 6, 7, 4, 7, 5, 5, 5,
Still not sure I understand. But here is what I think you might mean:
# Your data
mat <- structure(c(5, 6, 5, 5, 4, 3, 6, 7, 4, 7, 5, 5, 5, 5, 6, 5, 5,
4, 3, 6, 7, 4, 7, 5, 5, 5, 6, 5, 4, 5, 5, 7, 5, 6, 3, 5, 6, 7,
6, 6, 5, 4, 5, 5, 7, 5, 6, 3, 5, 6, 7, 6), .Dim = c(26L, 2L))
# Create a square ma
Since order is not important to you, you can order your pairs (e.g. decreasing)
before compiling the frequencies.
But I don't understand the second part about values "that do not appear in the
matrix". Do you mean you want to assess all combinations? If that's the case I
would think about a hash
Hello,
I have a matrix mat (see dput(mat))
> mat
[,1] [,2]
[1,]56
[2,]65
[3,]54
[4,]55
I want the frequencies of the pairs in a new matrix, whereas the
combination 5 and 6 is the same as 6 and 5 (see the first two rows of mat).
In other words: Wha
8 matches
Mail list logo