简体   繁体   中英

Reading Spss Data file in R

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM