R/poLCA.compress.R

Defines functions poLCA.compress

poLCA.compress <-
function(y) {
    ym.sorted <- y[do.call(order,data.frame(y)),]
    vars <- ncol(ym.sorted)
    datamat <- ym.sorted[1,]
    freq <- 1
    curpos <- 1
    for (i in 2:nrow(ym.sorted)) {
        if (sum(ym.sorted[i,] == ym.sorted[i-1,])==vars) {
            freq[curpos] <- freq[curpos]+1
        } else {
            datamat <- rbind(datamat,ym.sorted[i,])
            freq <- c(freq,1)
            curpos <- curpos+1
        }
    }
    rownames(datamat) <- c(1:length(freq))
    ret <- list(datamat=datamat,freq=freq)
    return(ret)
}

Try the poLCA package in your browser

Any scripts or data that you put into this service are public.

poLCA documentation built on April 25, 2022, 5:06 p.m.