4

i am using Expss pakage . df<-read_spss("test.SAV") I shows the following:

Warning message: In foreign::read.spss(enc2native(file), use.value.labels = FALSE, : Tally.SAV: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables

It shows 4174 Variables in environment Panel.Actual Number of Variables in the Data file around 400. Can anyone among you please help me on this.

s__
  • 9,270
  • 3
  • 27
  • 45
Divya
  • 47
  • 7
  • 2
    https://stat.ethz.ch/R-manual/R-devel/library/foreign/html/read.spss.html , this will help you to handle this error. – Hunaidkhan Dec 10 '18 at 11:05

1 Answers1

1

As mentioned in the comment foreign::read.spss split SPSS long (>255 chars) characters variables into the several columns. If the such columns are empty you can drop them without any issues. Convenience function for this:

remove_empty_characters_after_foreign = function(data){
    empty_chars = vapply(data, FUN = function(column) is.character(column) & all(is.na(column)), FUN.VALUE = logical(1))
    additional_chars = grepl("00\\d$", colnames(data), perl = TRUE)
    to_remove = empty_chars & additional_chars
    if(any(to_remove)){
        message(paste0("Removing ", paste(colnames(data)[to_remove], collapse = ", "),"..."))
    }
    data[,!to_remove, drop = FALSE]

}

df = remove_empty_characters_after_foreign(df)
Gregory Demin
  • 4,596
  • 2
  • 20
  • 20