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.