[R] Reading SPSS: underlying numerical codes

Michael Bibo michael_bibo at health.qld.gov.au
Fri Apr 13 03:38:20 CEST 2012


Marion Wenty <marion.wenty <at> gmail.com> writes:


> I have got a question concerning the underlying numerical codes when
> reading an SPSS file into R.
> 
> I used the package foreign and when I look at a variable I get the verbal
> codes.
> 
> I would like to know how it is possible to get the underlying numerical
> codes as output, which are the same as in my SPSS file.
> 


You don't need to import both numerical and text values;  
R can automatically assign numerical values for 
factors: see ?as.numeric.

The default sorting of factor levels in R is alphabetical.  
To change this, see the "levels" argument of the 
factor command: ?factor


Hope this helps,

Michael Bibo
Queensland Health



More information about the R-help mailing list