Re: [R] Compact Indicator Matrices

2008-05-12 Thread amarkos
Thanks. It works!

I think I found another solution, working straight with the indicator
matrix.

 count - factor(table(apply(ind, 1, paste, collapse=)))

However, that way I can't store the indices of the collapsed rows.

-Angelos Markos

__
R-help@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.


Re: [R] Compact Indicator Matrices

2008-05-11 Thread amarkos
On May 11, 4:47 pm, Douglas Bates [EMAIL PROTECTED] wrote:

 Do you mean that you want to collapse similar rows into a single row
 and perhaps a count of the number of times that this row occurs?

Let me rephrase the problem by providing an example.

Input:

A =
  [,1] [,2]
 [1,]11
 [2,]13
 [3,]21
 [4,]12
 [5,]21
 [6,]12
 [7,]11
 [8,]12
 [9,]13
[10,]21

# Indicator matrix
A - data.frame(lapply(data.frame(obj), as.factor))

nocases - dim(obj)[1]
novars  - dim(obj)[2]

# variable levels
levels.n - sapply(obj, nlevels)
n- cumsum(levels.n)

# Indicator matrix calculations
Z- matrix(0, nrow = nocases, ncol = n[length(n)])
newdat   - lapply(obj, as.numeric)
offset   - (c(0, n[-length(n)]))
for (i in 1:novars)
  Z[1:nocases + (nocases * (offset[i] + newdat[[i]] - 1))] - 1

###

Output:

Z =

[,1] [,2] [,3] [,4] [,5]
 [1,]10100
 [2,]10001
 [3,]01100
 [4,]10010
 [5,]01100
 [6,]10010
 [7,]10100
 [8,]10010
 [9,]10001
[10,]01100


Z is an indicator matrix in the Multiple Correspondence Analysis
framework.
My problem is to collapse identical rows (e.g. 2 and 9) into a single
row and
store the row ids.

__
R-help@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.


[R] Compact Indicator Matrices

2008-05-10 Thread amarkos
An indicator matrix is a binary matrix with orthogonal columns whose
rows sum to 1. A row of this matrix could be [0 1 0 0]. My problem is
to group the similar rows (profiles) so that to create a compact form
of the matrix.

Is there an R function that deals with this problem or do I have to
write it from scratch?

Thanks,
Angelos Markos
Dr. Applied Informatics,
University of Macedonia, Greece

__
R-help@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.