Skip to content

Commit

Permalink
Make codebook work with factors that have empty levels
Browse files Browse the repository at this point in the history
  • Loading branch information
melff committed Jul 30, 2020
1 parent bf6cc50 commit bb60f2c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/DESCRIPTION
@@ -1,8 +1,8 @@
Package: memisc
Type: Package
Title: Management of Survey Data and Presentation of Analysis Results
Version: 0.99.26
Date: 2020-07-28
Version: 0.99.26.1
Date: 2020-07-30
Author: Martin Elff (with contributions from Christopher N. Lawrence, Dave Atkins, Jason W. Morgan, Achim Zeileis)
Maintainer: Martin Elff <memisc@elff.eu>
Description: An infrastructure for the management of survey data including
Expand Down
12 changes: 10 additions & 2 deletions pkg/R/codebook-methods.R
Expand Up @@ -196,7 +196,13 @@ setMethod("codebookEntry","ANY",function(x,weights,unweighted=TRUE,...){
)
})


rwnexp <- function(mat,nms){
res <- array(0,c(length(nms),ncol(mat)),
dimnames=list(nms,colnames(mat)))
rn <- rownames(mat)
res[rn,] <- mat
return(res)
}

codebookTable_factor <- function(x,weights=NULL,...){

Expand All @@ -205,7 +211,9 @@ codebookTable_factor <- function(x,weights=NULL,...){

isna <- is.na(x)
counts <- rowsum(weights[!isna],x[!isna])

lev <- levels(x)
counts <- rwnexp(counts,lev)

NAs <- sum(weights*isna)

tab <- cbind(counts,100*counts/sum(counts))
Expand Down
4 changes: 4 additions & 0 deletions pkg/inst/ChangeLog
@@ -1,3 +1,7 @@
2020-07-30:
- Bugfix: Make codebook work with factors that have empty levels (i.e. no
observations for certain levels).

2020-07-28:
- Added 'mtable' support for 'clmm' objects (package "ordinal"") and improved
support for 'merMod' objects (package "lme4").
Expand Down

0 comments on commit bb60f2c

Please sign in to comment.