Rev 8505 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
R Under development (unstable) (2026-01-18 r89306) -- "Unsuffered Consequences"Copyright (C) 2026 The R Foundation for Statistical ComputingPlatform: x86_64-pc-linux-gnuR is free software and comes with ABSOLUTELY NO WARRANTY.You are welcome to redistribute it under certain conditions.Type 'license()' or 'licence()' for distribution details.R is a collaborative project with many contributors.Type 'contributors()' for more information and'citation()' on how to cite R or R packages in publications.Type 'demo()' for some demos, 'help()' for on-line help, or'help.start()' for an HTML browser interface to help.Type 'q()' to quit R.> library(foreign)>> sample100 <- read.spss("sample100.sav",FALSE)> summary(sample100)Length Class ModeYEAR 100 -none- numericDISTRICT 100 -none- numericCAMPUS 100 -none- numericDNAME 100 -none- characterCNAME 100 -none- characterSEX 100 -none- characterDISADVG 100 -none- characterETHNICTY 100 -none- characterSTUID 100 -none- characterTLIMTH 100 -none- numericGRADE 100 -none- numeric> str(sample100)List of 11$ YEAR : num [1:100] 99 94 94 95 96 97 98 99 94 95 ...$ DISTRICT: num [1:100] 57914 57914 57914 57914 57914 ...$ CAMPUS : num [1:100] 57914045 57914106 57914110 57914123 57914117 ...$ DNAME : chr [1:100] "MESQUITE ISD " "MESQUITE ISD " "MESQUITE ISD " "MESQUITE ISD " ...$ CNAME : chr [1:100] "A C NEW MIDDLE " "MCWHORTER EL " "RUTHERFORD EL " "JOEY M PIRRUNG " ...$ SEX : chr [1:100] "F" "F" " " "F" ...$ DISADVG : chr [1:100] "NO " "NO " " " "NO " ...$ ETHNICTY: chr [1:100] "WHITE " "WHITE " " " "HISPANIC" ...$ STUID : chr [1:100] "00614371S" "00614372S" "00614373S" "00614373S" ...$ TLIMTH : num [1:100] 90 86 67 77 77 79 86 87 89 85 ...$ GRADE : num [1:100] 8 3 3 4 5 6 7 8 3 4 ...- attr(*, "label.table")=List of 11..$ YEAR : NULL..$ DISTRICT: NULL..$ CAMPUS : NULL..$ DNAME : NULL..$ CNAME : NULL..$ SEX : NULL..$ DISADVG : NULL..$ ETHNICTY: NULL..$ STUID : NULL..$ TLIMTH : NULL..$ GRADE : NULL- attr(*, "variable.labels")= Named chr [1:11] "YEAR OF ADMINISTRATION" "COUNTY DISTRICT NUMBER" "COUNTY DISTRICT CAMPUS NUMBER" "DISTRICT NAME" .....- attr(*, "names")= chr [1:11] "YEAR" "DISTRICT" "CAMPUS" "DNAME" ...> d.sample100 <- data.frame(sample100,stringsAsFactors=TRUE)> summary(d.sample100)YEAR DISTRICT CAMPUS DNAMEMin. : 94.0 Min. : 57905 Min. : 57905126 DALLAS ISD : 11st Qu.: 95.0 1st Qu.: 57914 1st Qu.: 57914046 HARMONY ISD : 1Median : 96.0 Median : 57914 Median : 57914112 MESQUITE ISD :96Mean : 115.4 Mean : 59644 Mean : 59644015 SUNNYVALE ISD : 23rd Qu.: 98.0 3rd Qu.: 57914 3rd Qu.: 57914125Max. :2000.0 Max. :230905 Max. :230905101CNAME SEX DISADVG ETHNICTY STUIDJ C AUSTIN EL :23 : 4 : 4 : 4 00614373S: 6R S KIMBROUGH M:12 F:62 NO :90 HISPANIC: 3 00614378S: 6WILKINSON MIDDL: 9 M:34 YES: 6 OTHER : 2 00614379S: 6VERNON PRICE EL: 7 WHITE :91 00614389S: 6TISINGER EL : 6 00614397S: 6THOMPSON EL : 5 00614403S: 6(Other) :38 (Other) :64TLIMTH GRADEMin. :54.00 Min. :3.001st Qu.:74.00 1st Qu.:4.00Median :84.00 Median :5.00Mean :80.16 Mean :5.373rd Qu.:87.00 3rd Qu.:7.00Max. :93.00 Max. :8.00> s100 <- sample100> sample100 <- read.spss("sample100.por",FALSE)> stopifnot(identical(s100, sample100)) # no need for further summary() etc>> pbc <- read.spss("pbc.sav",FALSE)> summary(pbc)Length Class ModeAGE 418 -none- numericALB 418 -none- numericALKPHOS 418 -none- numericASCITES 418 -none- numericBILI 418 -none- numericCHOL 418 -none- numericEDEMA 418 -none- numericEDTRT 418 -none- numericHEPMEG 418 -none- numericTIME 418 -none- numericPLATELET 418 -none- numericPROTIME 418 -none- numericSEX 418 -none- numericSGOT 418 -none- numericSPIDERS 418 -none- numericSTAGE 418 -none- numericSTATUS 418 -none- numericTRT 418 -none- numericTRIG 418 -none- numericCOPPER 418 -none- numeric> str(pbc)List of 20$ AGE : num [1:418] 58.8 56.4 70.1 54.7 38.1 ...$ ALB : num [1:418] 2.6 4.14 3.48 2.54 3.53 3.98 4.09 4 3.08 2.74 ...$ ALKPHOS : num [1:418] 1718 7395 516 6122 671 ...$ ASCITES : num [1:418] 1 0 0 0 0 0 0 0 0 1 ...$ BILI : num [1:418] 14.5 1.1 1.4 1.8 3.4 0.8 1 0.3 3.2 12.6 ...$ CHOL : num [1:418] 261 302 176 244 279 248 322 280 562 200 ...$ EDEMA : num [1:418] 1 0 1 1 0 0 0 0 0 1 ...$ EDTRT : num [1:418] 1 0 0.5 0.5 0 0 0 0 0 1 ...$ HEPMEG : num [1:418] 1 1 0 1 1 1 1 0 0 0 ...$ TIME : num [1:418] 400 4500 1012 1925 1504 ...$ PLATELET: num [1:418] 190 221 151 183 136 -9 204 373 251 302 ...$ PROTIME : num [1:418] 12.2 10.6 12 10.3 10.9 11 9.7 11 11 11.5 ...$ SEX : num [1:418] 1 1 0 1 1 1 1 1 1 1 ...$ SGOT : num [1:418] 137.9 113.5 96.1 60.6 113.2 ...$ SPIDERS : num [1:418] 1 1 0 1 1 0 0 0 1 1 ...$ STAGE : num [1:418] 4 3 4 4 3 3 3 3 2 4 ...$ STATUS : num [1:418] 1 0 1 1 0 1 0 1 1 1 ...$ TRT : num [1:418] 1 1 1 1 2 2 2 2 1 2 ...$ TRIG : num [1:418] 172 88 55 92 72 63 213 189 88 143 ...$ COPPER : num [1:418] 156 54 210 64 143 50 52 52 79 140 ...- attr(*, "label.table")=List of 20..$ AGE : NULL..$ ALB : NULL..$ ALKPHOS : NULL..$ ASCITES : NULL..$ BILI : NULL..$ CHOL : NULL..$ EDEMA : NULL..$ EDTRT : NULL..$ HEPMEG : NULL..$ TIME : NULL..$ PLATELET: NULL..$ PROTIME : NULL..$ SEX : NULL..$ SGOT : NULL..$ SPIDERS : NULL..$ STAGE : NULL..$ STATUS : NULL..$ TRT : NULL..$ TRIG : NULL..$ COPPER : NULL> d.pbc <- data.frame(pbc)> summary(d.pbc)AGE ALB ALKPHOS ASCITESMin. :26.28 Min. :1.960 Min. : -9 Min. :-9.0001st Qu.:42.83 1st Qu.:3.243 1st Qu.: -9 1st Qu.:-9.000Median :51.00 Median :3.530 Median : 1009 Median : 0.000Mean :50.74 Mean :3.497 Mean : 1478 Mean :-2.2253rd Qu.:58.24 3rd Qu.:3.770 3rd Qu.: 1708 3rd Qu.: 0.000Max. :78.44 Max. :4.640 Max. :13862 Max. : 1.000BILI CHOL EDEMA EDTRTMin. : 0.300 Min. : -9.0 Min. :0.0000 Min. :0.00001st Qu.: 0.800 1st Qu.: -9.0 1st Qu.:0.0000 1st Qu.:0.0000Median : 1.400 Median : 252.5 Median :0.0000 Median :0.0000Mean : 3.221 Mean : 248.2 Mean :0.1196 Mean :0.10053rd Qu.: 3.400 3rd Qu.: 347.8 3rd Qu.:0.0000 3rd Qu.:0.0000Max. :28.000 Max. :1775.0 Max. :1.0000 Max. :1.0000HEPMEG TIME PLATELET PROTIME SEXMin. :-9.0 Min. : 41 Min. : -9.0 Min. : 9.00 Min. :-9.0001st Qu.:-9.0 1st Qu.:1093 1st Qu.:181.0 1st Qu.:10.00 1st Qu.:-9.000Median : 0.0 Median :1730 Median :248.0 Median :10.60 Median : 1.000Mean :-1.9 Mean :1918 Mean :250.0 Mean :10.73 Mean :-1.6223rd Qu.: 1.0 3rd Qu.:2614 3rd Qu.:315.5 3rd Qu.:11.10 3rd Qu.: 1.000Max. : 1.0 Max. :4795 Max. :721.0 Max. :18.00 Max. : 1.000SGOT SPIDERS STAGE STATUSMin. : -9.00 Min. :-9.000 Min. :-9.00000 Min. :0.00001st Qu.: -9.00 1st Qu.:-9.000 1st Qu.:-9.00000 1st Qu.:0.0000Median : 90.45 Median : 0.000 Median : 3.00000 Median :0.0000Mean : 89.20 Mean :-2.067 Mean :-0.01914 Mean :0.38523rd Qu.:135.75 3rd Qu.: 0.000 3rd Qu.: 4.00000 3rd Qu.:1.0000Max. :457.25 Max. : 1.000 Max. : 4.00000 Max. :1.0000TRT TRIG COPPERMin. :-9.000 Min. : -9.0 Min. : -9.001st Qu.:-9.000 1st Qu.: -9.0 1st Qu.: -9.00Median : 1.000 Median : 85.0 Median : 50.50Mean :-1.167 Mean : 81.2 Mean : 70.093rd Qu.: 2.000 3rd Qu.:127.8 3rd Qu.:100.75Max. : 2.000 Max. :598.0 Max. :588.00> pbco <- read.spss("pbcold.sav",FALSE)> stopifnot(identical(pbc, pbco))> ## summary(pbco)> ## str(pbco)> ## d.pbco <- data.frame(pbco)> ## summary(d.pbco)> pbc. <- read.spss("pbc.por",FALSE)> summary(pbc.)Length Class ModeAGE 418 -none- numericALB 418 -none- numericALKPHOS 418 -none- numericASCITES 418 -none- numericBILI 418 -none- numericCHOL 418 -none- numericEDEMA 418 -none- numericEDTRT 418 -none- numericHEPMEG 418 -none- numericTIME 418 -none- numericPLATELET 418 -none- numericPROTIME 418 -none- numericSEX 418 -none- numericSGOT 418 -none- numericSPIDERS 418 -none- numericSTAGE 418 -none- numericSTATUS 418 -none- numericTRT 418 -none- numericTRIG 418 -none- numericCOPPER 418 -none- numeric> str(pbc.) # has variable.labelsList of 20$ AGE : num [1:418] 58.8 56.4 70.1 54.7 38.1 ...$ ALB : num [1:418] 2.6 4.14 3.48 2.54 3.53 3.98 4.09 4 3.08 2.74 ...$ ALKPHOS : num [1:418] 1718 7395 516 6122 671 ...$ ASCITES : num [1:418] 1 0 0 0 0 0 0 0 0 1 ...$ BILI : num [1:418] 14.5 1.1 1.4 1.8 3.4 0.8 1 0.3 3.2 12.6 ...$ CHOL : num [1:418] 261 302 176 244 279 248 322 280 562 200 ...$ EDEMA : num [1:418] 1 0 1 1 0 0 0 0 0 1 ...$ EDTRT : num [1:418] 1 0 0.5 0.5 0 0 0 0 0 1 ...$ HEPMEG : num [1:418] 1 1 0 1 1 1 1 0 0 0 ...$ TIME : num [1:418] 400 4500 1012 1925 1504 ...$ PLATELET: num [1:418] 190 221 151 183 136 -9 204 373 251 302 ...$ PROTIME : num [1:418] 12.2 10.6 12 10.3 10.9 11 9.7 11 11 11.5 ...$ SEX : num [1:418] 1 1 0 1 1 1 1 1 1 1 ...$ SGOT : num [1:418] 137.9 113.5 96.1 60.6 113.2 ...$ SPIDERS : num [1:418] 1 1 0 1 1 0 0 0 1 1 ...$ STAGE : num [1:418] 4 3 4 4 3 3 3 3 2 4 ...$ STATUS : num [1:418] 1 0 1 1 0 1 0 1 1 1 ...$ TRT : num [1:418] 1 1 1 1 2 2 2 2 1 2 ...$ TRIG : num [1:418] 172 88 55 92 72 63 213 189 88 143 ...$ COPPER : num [1:418] 156 54 210 64 143 50 52 52 79 140 ...- attr(*, "label.table")=List of 20..$ AGE : NULL..$ ALB : NULL..$ ALKPHOS : NULL..$ ASCITES : NULL..$ BILI : NULL..$ CHOL : NULL..$ EDEMA : NULL..$ EDTRT : NULL..$ HEPMEG : NULL..$ TIME : NULL..$ PLATELET: NULL..$ PROTIME : NULL..$ SEX : NULL..$ SGOT : NULL..$ SPIDERS : NULL..$ STAGE : NULL..$ STATUS : NULL..$ TRT : NULL..$ TRIG : NULL..$ COPPER : NULL- attr(*, "variable.labels")= Named chr [1:20] " " " " " " " " .....- attr(*, "names")= chr [1:20] "AGE" "ALB" "ALKPHOS" "ASCITES" ...> stopifnot(all.equal(d.pbc, data.frame(pbc.), tolerance = 1e-15))>> electric.s <- read.spss(system.file("files", "electric.sav", package = "foreign"), TRUE, TRUE)> electric.p <- read.spss("electric.por",TRUE,TRUE)> electric.s4 <- read.spss(system.file("files", "electric.sav", package = "foreign"), TRUE, TRUE, max.value.labels = 4)> smmry <- summary(electric.s)> if (getRversion() < "4.6.0") # "backport" NA's -> NAs to match reference output+ smmry <- sub("NA's", "NAs ", smmry, fixed = TRUE)> smmryCASEID FIRSTCHD AGE DBP58Min. : 1.00 NO CHD :120 Min. :40.0 Min. : 65.001st Qu.: 73.75 SUDDEN DEATH: 36 1st Qu.:45.0 1st Qu.: 80.00Median : 144.50 NONFATALMI : 72 Median :48.0 Median : 87.00Mean : 572.94 FATAL MI : 9 Mean :47.8 Mean : 88.793rd Qu.:1042.25 OTHER CHD : 3 3rd Qu.:51.0 3rd Qu.: 96.50Max. :2098.00 Max. :54.0 Max. :160.00NAs :1EDUYR CHOL58 CGT58 HT58Min. : 6.00 Min. :106.0 Min. : 0.00 Min. :60.901st Qu.: 9.75 1st Qu.:228.8 1st Qu.: 0.00 1st Qu.:66.50Median :12.00 Median :261.0 Median :10.00 Median :68.15Mean :11.66 Mean :264.1 Mean :11.58 Mean :68.513rd Qu.:14.00 3rd Qu.:293.2 3rd Qu.:20.00 3rd Qu.:70.20Max. :18.00 Max. :515.0 Max. :60.00 Max. :77.00NAs :28 NAs :1WT58 DAYOFWK VITAL10 FAMHXCVR CHDMin. :123.0 SUNDAY : 19 ALIVE:179 NO :178 Min. :0.01st Qu.:156.0 TUESDAY : 19 DEAD : 61 YES: 62 1st Qu.:0.0Median :171.0 WEDNSDAY: 17 Median :0.5Mean :173.4 SATURDAY: 16 Mean :0.53rd Qu.:187.0 THURSDAY: 15 3rd Qu.:1.0Max. :278.0 (Other) : 24 Max. :1.0NAs :130> ii <- c(2,10)> vl <- list(FIRSTCHD = c("OTHER CHD"= 6, "FATAL MI"= 5, "NONFATALMI"= 3,+ "SUDDEN DEATH" = 2, "NO CHD" = 1),+ DAYOFWK = c(SATURDAY=7, FRIDAY=6, THURSDAY=5,+ WEDNSDAY=4, TUESDAY=3, MONDAY=2, SUNDAY=1))> stopifnot(identical(electric.s, electric.p),+ identical(electric.s[-ii], electric.s4[-ii]),+ identical(vl, lapply(electric.s4[ii], attr, "value.labels")),+ identical(lapply(vl, names),+ lapply(electric.s[ii], function(.) rev(levels(.)))))>>> ## after "long label patch":> ## (from <https://stat.ethz.ch/pipermail/r-devel/2008-July/050165.html>)>> ##invisible(Sys.setlocale (locale="C")) ## to resolve locale problem # ??> ldat <- read.spss("spss_long.sav", to.data.frame=TRUE)> ldatvariable1 variable21 1 12 2 13 2 3> nnms <- nms <- names(ldat)> names(nnms) <- nms> stopifnot(identical(nms, c("variable1", "variable2")),+ identical(nnms, attr(ldat, "variable.labels")))>>> ## some new arkward testcases for problems found in foreign <= 0.8-68 and duplicated value labels in general:>> ## Expect lots of warnings as value labels (corresponding to R factor labels) are uncomplete,> ## and an unsupported long string variable is present in the data>> setwd(system.file("files", package = "foreign"))> sav <- "testdata.sav">> x.nodat <- read.spss(file=sav, to.data.frame = FALSE, reencode="UTF-8")re-encoding from UTF-8Warning messages:1: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :testdata.sav: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables2: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :Undeclared level(s) -1 added in variable: factor_numeric3: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :Duplicated levels in factor factor_n_duplicated: A4: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :Undeclared level(s) 2, 3, 4 added in variable: factor_n_undeclared5: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :Undeclared level(s) 0, 3 added in variable: factor_n_undeclared26: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :Undeclared level(s) ä, ö added in variable: factor_s_duplicated7: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :Duplicated levels in factor factor_s_duplicated: A8: In read.spss(file = sav, to.data.frame = FALSE, reencode = "UTF-8") :Undeclared level(s) perhaps added in variable: factor_s_undeclared> str(x.nodat)List of 17$ numeric : num [1:5] 1 2 3 NA 3$ numeric_long_label : num [1:5] 1 2 3.33 4 NA$ factor_numeric : Factor w/ 6 levels "-1","strongly disagree",..: 2 3 4 1 NA$ factor_n_long_value_label: Factor w/ 2 levels "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop",..: 1 2 NA 2 1$ factor_n_coded_miss : Factor w/ 6 levels "strongly disagree",..: 1 2 6 5 NA$ factor_n_duplicated : Factor w/ 3 levels "A","A_duplicated_2",..: 1 1 2 NA 3$ factor_n_undeclared : Factor w/ 5 levels "strongly disagree",..: 1 2 4 3 1$ factor_n_undeclared2 : Factor w/ 4 levels "0","yes","no",..: 1 4 NA 1 4$ string : chr [1:5] "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum s"| __truncated__ "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrib"| __truncated__ " "| __truncated__ " "| __truncated__ ...$ string_500 : chr [1:5] "A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy "| __truncated__ " "| __truncated__ "Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind t"| __truncated__ " "| __truncated__ ...$ STRIN0 : chr [1:5] ", my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I s"| __truncated__ " "| __truncated__ "r place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of"| __truncated__ " "| __truncated__ ...$ string_miss : chr [1:5] "a " "c " "b " "g " ...$ factor_s_coded_miss : Factor w/ 3 levels "female","male",..: 2 1 NA 2 3$ factor_s_duplicated : Factor w/ 5 levels "A","A_duplicated_b",..: 1 5 4 NA NA$ factor_s_undeclared : Factor w/ 3 levels "no","perhaps",..: 3 1 2 NA 3$ factor_s_undeclared2 : Factor w/ 2 levels "no","yes": NA NA NA NA NA$ date : num [1:5] 1.27e+10 1.37e+10 1.37e+10 NA NA- attr(*, "label.table")=List of 17..$ numeric : NULL..$ numeric_long_label : NULL..$ factor_numeric : Named chr [1:5] "5" "4" "3" "2" ..... ..- attr(*, "names")= chr [1:5] "strongly agree" "agree" "neither agree nor disagree" "disagree" .....$ factor_n_long_value_label: Named chr [1:2] "2" "1".. ..- attr(*, "names")= chr [1:2] "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ! \" # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \\ ] ^ _ ` { | } ~ €" "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop"..$ factor_n_coded_miss : Named chr [1:6] "99" "5" "4" "3" ..... ..- attr(*, "names")= chr [1:6] "no answer" "strongly agree" "agree" "neither agree nor disagree" .....$ factor_n_duplicated : Named chr [1:3] "3" "2" "1".. ..- attr(*, "names")= chr [1:3] "B" "A" "A"..$ factor_n_undeclared : Named chr [1:2] "5" "1".. ..- attr(*, "names")= chr [1:2] "strongly agree" "strongly disagree"..$ factor_n_undeclared2 : Named chr [1:2] "2" "1".. ..- attr(*, "names")= chr [1:2] "no" "yes"..$ string : NULL..$ string_500 : NULL..$ STRIN0 : NULL..$ string_miss : NULL..$ factor_s_coded_miss : Named chr [1:3] "u " "m " "f ".. ..- attr(*, "names")= chr [1:3] "unknown" "male" "female"..$ factor_s_duplicated : Named chr [1:3] "c " "b " "a ".. ..- attr(*, "names")= chr [1:3] "C" "A" "A"..$ factor_s_undeclared : Named chr [1:2] "y " "n ".. ..- attr(*, "names")= chr [1:2] "yes" "no"..$ factor_s_undeclared2 : Named chr [1:2] "y " "n ".. ..- attr(*, "names")= chr [1:2] "yes" "no"..$ date : NULL- attr(*, "variable.labels")= Named chr [1:17] "numeric variable" "numeric variable with long label: this variable hat five observations (one is missing). All values between 1 an"| __truncated__ "numeric factor with missing range" "numeric factor with long value labels" .....- attr(*, "names")= chr [1:17] "numeric" "numeric_long_label" "factor_numeric" "factor_n_long_value_label" ...- attr(*, "missings")=List of 17..$ numeric :List of 1.. ..$ type: chr "none"..$ numeric_long_label :List of 2.. ..$ type : chr "range".. ..$ value: num [1:2] 1 2..$ factor_numeric :List of 2.. ..$ type : chr "range".. ..$ value: num [1:2] -1 0..$ factor_n_long_value_label:List of 1.. ..$ type: chr "none"..$ factor_n_coded_miss :List of 2.. ..$ type : chr "one".. ..$ value: num 99..$ factor_n_duplicated :List of 1.. ..$ type: chr "none"..$ factor_n_undeclared :List of 1.. ..$ type: chr "none"..$ factor_n_undeclared2 :List of 1.. ..$ type: chr "none"..$ string :List of 1.. ..$ type: chr "none"..$ string_500 :List of 1.. ..$ type: chr "none"..$ STRIN0 :List of 1.. ..$ type: chr "none"..$ string_miss :List of 2.. ..$ type : chr "two".. ..$ value: chr [1:2] "a b " "b "..$ factor_s_coded_miss :List of 2.. ..$ type : chr "three".. ..$ value: chr [1:3] "u v w \b" "v w \b" "w \b"..$ factor_s_duplicated :List of 1.. ..$ type: chr "none"..$ factor_s_undeclared :List of 1.. ..$ type: chr "none"..$ factor_s_undeclared2 :List of 1.. ..$ type: chr "none"..$ date :List of 1.. ..$ type: chr "none"- attr(*, "codepage")= int 65001>> x.sort <- read.spss(file=sav, to.data.frame = TRUE, reencode="UTF-8",+ stringsAsFactors=TRUE)re-encoding from UTF-8Warning messages:1: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8", :testdata.sav: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables2: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8", :Duplicated levels in factor factor_n_duplicated: A3: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8", :Undeclared level(s) 2, 3, 4 added in variable: factor_n_undeclared4: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8", :Undeclared level(s) 0, 3 added in variable: factor_n_undeclared25: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8", :Undeclared level(s) ä, ö added in variable: factor_s_duplicated6: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8", :Duplicated levels in factor factor_s_duplicated: A7: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8", :Undeclared level(s) perhaps added in variable: factor_s_undeclared> str(x.sort)'data.frame': 5 obs. of 17 variables:$ numeric : num 1 2 3 NA 3$ numeric_long_label : num NA NA 3.33 4 NA$ factor_numeric : Factor w/ 5 levels "strongly disagree",..: 1 2 3 NA NA$ factor_n_long_value_label: Factor w/ 2 levels "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnop",..: 1 2 NA 2 1$ factor_n_coded_miss : Factor w/ 5 levels "strongly disagree",..: 1 2 NA 5 NA$ factor_n_duplicated : Factor w/ 3 levels "A","A_duplicated_2",..: 1 1 2 NA 3$ factor_n_undeclared : Factor w/ 5 levels "strongly disagree",..: 1 2 4 3 1$ factor_n_undeclared2 : Factor w/ 4 levels "0","yes","no",..: 1 4 NA 1 4$ string : Factor w/ 4 levels " "| __truncated__,..: 3 4 1 1 2$ string_500 : Factor w/ 4 levels " "| __truncated__,..: 2 1 3 1 4$ STRIN0 : Factor w/ 4 levels " "| __truncated__,..: 2 1 4 1 3$ string_miss : Factor w/ 4 levels " ","a ",..: 2 3 NA 4 1$ factor_s_coded_miss : Factor w/ 3 levels "female","male",..: 2 1 NA 2 3$ factor_s_duplicated : Factor w/ 5 levels "A","A_duplicated_b",..: 1 5 4 NA NA$ factor_s_undeclared : Factor w/ 3 levels "no","perhaps",..: 3 1 2 NA 3$ factor_s_undeclared2 : Factor w/ 2 levels "no","yes": NA NA NA NA NA$ date : num 1.27e+10 1.37e+10 1.37e+10 NA NA- attr(*, "variable.labels")= Named chr [1:17] "numeric variable" "numeric variable with long label: this variable hat five observations (one is missing). All values between 1 an"| __truncated__ "numeric factor with missing range" "numeric factor with long value labels" .....- attr(*, "names")= chr [1:17] "numeric" "numeric_long_label" "factor_numeric" "factor_n_long_value_label" ...- attr(*, "codepage")= int 65001> x.append <- read.spss(file=sav, to.data.frame = TRUE,+ add.undeclared.levels = "append", reencode="UTF-8")re-encoding from UTF-8Warning messages:1: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "append", :testdata.sav: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables2: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "append", :Duplicated levels in factor factor_n_duplicated: A3: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "append", :Undeclared level(s) 2, 3, 4 added in variable: factor_n_undeclared4: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "append", :Undeclared level(s) 0, 3 added in variable: factor_n_undeclared25: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "append", :Undeclared level(s) ä, ö added in variable: factor_s_duplicated6: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "append", :Duplicated levels in factor factor_s_duplicated: A7: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "append", :Undeclared level(s) perhaps added in variable: factor_s_undeclared> x.no <- read.spss(file=sav, to.data.frame = TRUE,+ add.undeclared.levels = "no", reencode="UTF-8")re-encoding from UTF-8Warning messages:1: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "no", :testdata.sav: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables2: In read.spss(file = sav, to.data.frame = TRUE, add.undeclared.levels = "no", :Duplicated levels in factor factor_n_duplicated: A>> levels(x.sort$factor_n_undeclared)[1] "strongly disagree" "2" "3"[4] "4" "strongly agree"> levels(x.append$factor_n_undeclared)[1] "strongly disagree" "strongly agree" "2"[4] "3" "4"> str(x.no$factor_n_undeclared)num [1:5] 1 2 4 3 1- attr(*, "value.labels")= Named chr [1:2] "5" "1"..- attr(*, "names")= chr [1:2] "strongly agree" "strongly disagree">>> ### Examples for duplicated.value.labels:> ## duplicated.value.labels = "append" (default)> x.append <- read.spss(file=sav, to.data.frame=TRUE, reencode="UTF-8")re-encoding from UTF-8Warning messages:1: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8") :testdata.sav: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables2: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8") :Duplicated levels in factor factor_n_duplicated: A3: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8") :Undeclared level(s) 2, 3, 4 added in variable: factor_n_undeclared4: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8") :Undeclared level(s) 0, 3 added in variable: factor_n_undeclared25: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8") :Undeclared level(s) ä, ö added in variable: factor_s_duplicated6: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8") :Duplicated levels in factor factor_s_duplicated: A7: In read.spss(file = sav, to.data.frame = TRUE, reencode = "UTF-8") :Undeclared level(s) perhaps added in variable: factor_s_undeclared> ## duplicated.value.labels = "condense"> x.condense <- read.spss(file=sav, to.data.frame=TRUE,+ duplicated.value.labels = "condense", reencode="UTF-8")re-encoding from UTF-8Warning messages:1: In read.spss(file = sav, to.data.frame = TRUE, duplicated.value.labels = "condense", :testdata.sav: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables2: In read.spss(file = sav, to.data.frame = TRUE, duplicated.value.labels = "condense", :Duplicated levels in factor factor_n_duplicated: A3: In read.spss(file = sav, to.data.frame = TRUE, duplicated.value.labels = "condense", :Undeclared level(s) 2, 3, 4 added in variable: factor_n_undeclared4: In read.spss(file = sav, to.data.frame = TRUE, duplicated.value.labels = "condense", :Undeclared level(s) 0, 3 added in variable: factor_n_undeclared25: In read.spss(file = sav, to.data.frame = TRUE, duplicated.value.labels = "condense", :Undeclared level(s) ä, ö added in variable: factor_s_duplicated6: In read.spss(file = sav, to.data.frame = TRUE, duplicated.value.labels = "condense", :Duplicated levels in factor factor_s_duplicated: A7: In read.spss(file = sav, to.data.frame = TRUE, duplicated.value.labels = "condense", :Undeclared level(s) perhaps added in variable: factor_s_undeclared>> levels(x.append$factor_n_duplicated)[1] "A" "A_duplicated_2" "B"> levels(x.condense$factor_n_duplicated)[1] "A" "B">> as.numeric(x.append$factor_n_duplicated)[1] 1 1 2 NA 3> as.numeric(x.condense$factor_n_duplicated)[1] 1 1 1 NA 2>> ### ToDo:> ## Long Strings (>255 chars) are imported in consecutive separate variables> ## (see warning about subtype 14)> ## we should get that right in the import function in future versions> x <- read.spss(file=sav, to.data.frame=TRUE, stringsAsFactors=FALSE, reencode="UTF-8")re-encoding from UTF-8Warning messages:1: In read.spss(file = sav, to.data.frame = TRUE, stringsAsFactors = FALSE, :testdata.sav: Very long string record(s) found (record type 7, subtype 14), each will be imported in consecutive separate variables2: In read.spss(file = sav, to.data.frame = TRUE, stringsAsFactors = FALSE, :Duplicated levels in factor factor_n_duplicated: A3: In read.spss(file = sav, to.data.frame = TRUE, stringsAsFactors = FALSE, :Undeclared level(s) 2, 3, 4 added in variable: factor_n_undeclared4: In read.spss(file = sav, to.data.frame = TRUE, stringsAsFactors = FALSE, :Undeclared level(s) 0, 3 added in variable: factor_n_undeclared25: In read.spss(file = sav, to.data.frame = TRUE, stringsAsFactors = FALSE, :Undeclared level(s) ä, ö added in variable: factor_s_duplicated6: In read.spss(file = sav, to.data.frame = TRUE, stringsAsFactors = FALSE, :Duplicated levels in factor factor_s_duplicated: A7: In read.spss(file = sav, to.data.frame = TRUE, stringsAsFactors = FALSE, :Undeclared level(s) perhaps added in variable: factor_s_undeclared>> cat.long.string <- function(x, w=70) cat(paste(strwrap(x, width=w), "\n"))>> ## first part: x$string_500:> cat.long.string(x$string_500)A wonderful serenity has taken possession of my entire soul, likethese sweet mornings of spring which I enjoy with my whole heart. Iam alone, and feel the charm of existence in this spot, which wascreated for the bliss of souls like mine. I am so happyFar far away, behind the word mountains, far from the countriesVokalia and Consonantia, there live the blind texts. Separated theylive in Bookmarksgrove right at the coast of the Semantics, a largelanguage ocean. A small river named Duden flows by theiabc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ!"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrstuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* '<> #|;²³~ @`´ ©«» ¤¼× {} abc def ghi j> ## second part: x$STRIN0:> cat.long.string(x$STRIN0), my dear friend, so absorbed in the exquisite sense of mere tranquilexistence, that I neglect my talents. I should be incapable ofdrawing a single stroke at the present moment; and yet I feel that Inever was a greater artist than now.r place and supplies it with the necessary regelialia. It is aparadisematic country, in which roasted parts of sentences fly intoyour mouth.kl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /()=?* '<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrs tuv wxyz ABCDEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¤¼×{} abc def ghi jkl> ## complete long string:> long.string <- apply(x[,c("string_500", "STRIN0")], 1, paste, collapse="")> cat.long.string(long.string)A wonderful serenity has taken possession of my entire soul, likethese sweet mornings of spring which I enjoy with my whole heart. Iam alone, and feel the charm of existence in this spot, which wascreated for the bliss of souls like mine. I am so happy, my dearfriend, so absorbed in the exquisite sense of mere tranquilexistence, that I neglect my talents. I should be incapable ofdrawing a single stroke at the present moment; and yet I feel that Inever was a greater artist than now.Far far away, behind the word mountains, far from the countriesVokalia and Consonantia, there live the blind texts. Separated theylive in Bookmarksgrove right at the coast of the Semantics, a largelanguage ocean. A small river named Duden flows by their place andsupplies it with the necessary regelialia. It is a paradisematiccountry, in which roasted parts of sentences fly into your mouth.abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ!"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrstuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%& /() =?* '<> #|;²³~ @`´ ©«» ¤¼× {} abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKLMNO PQRS TUV WXYZ !"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¤¼× {} abc defghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL MNO PQRS TUV WXYZ !"§ $%&/() =?* '<> #|; ²³~ @`´ ©«» ¤¼× {} abc def ghi jkl>> proc.time()user system elapsed0.181 0.041 0.213