0

I am having problem while plotting missing/imputed values. When I try to run this code: (demo is the name of the dataset)

mice_plot <- aggr(demo, col=c('navyblue','yellow'),
                  numbers=TRUE, sortVars=TRUE,
                  labels=names(demo), cex.axis=.7,
                  gap=3, ylab=c("Missing data","Pattern"))

I get the following error:

Error in as.matrix.data.frame(X) : 
dims [product 284088] do not match the length of object [284121]

Please help. what does this mean?

Harshit Singh
  • 625
  • 5
  • 17

2 Answers2

0

Sounds like your columns of the data.frame have different numbers of rows

Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
0

Try looking here: https://www.r-bloggers.com/imputing-missing-data-with-r-mice-package/

This post uses the following code for the type of plot you are trying to do, and I was able to run it on a data set of mine without a problem:

library(VIM) aggr_plot <- aggr(data, col=c('navyblue','red'), numbers=TRUE, sortVars=TRUE, labels=names(data), cex.axis=.7, gap=3, ylab=c("Histogram of missing data","Pattern"))

As for the error you're getting, it seems to be with your data frame. Did you run any other code altering the DF?

wissem
  • 58
  • 8