Friday, October 12, 2018

Reading a SPSS file using R

SPSS files are created using the SPSS software from IBM. You could read these files using R provided you can install the 'haven' library from one of the CRAN sites.


Rlib_Haven.png


Install 'haven'
--------------
> install.packages("haven")
Warning in install.packages("haven") :
  'lib = "C:/Program Files/Microsoft/R Client/R_SERVER/library"' is not writable
also installing the dependencies ‘assertthat’, ‘lazyeval’, ‘Rcpp’, ‘readr’, ‘hms’, ‘tibble’, ‘BH’

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/assertthat_0.1.zip'
Content type 'application/zip' length 44884 bytes (43 KB)
downloaded 43 KB

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/lazyeval_0.2.0.zip'
Content type 'application/zip' length 137793 bytes (134 KB)
downloaded 134 KB

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/Rcpp_0.12.7.zip'
Content type 'application/zip' length 3265183 bytes (3.1 MB)
downloaded 3.1 MB

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/readr_1.0.0.zip'
Content type 'application/zip' length 1167814 bytes (1.1 MB)
downloaded 1.1 MB

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/hms_0.2.zip'
Content type 'application/zip' length 20730 bytes (20 KB)
downloaded 20 KB

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/tibble_1.2.zip'
Content type 'application/zip' length 614069 bytes (599 KB)
downloaded 599 KB

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/BH_1.60.0-2.zip'
Content type 'application/zip' length 15529292 bytes (14.8 MB)
downloaded 14.8 MB

trying URL 'https://mran.revolutionanalytics.com/snapshot/2016-11-01/bin/windows/contrib/3.3/haven_1.0.0.zip'
Content type 'application/zip' length 800532 bytes (781 KB)
downloaded 781 KB

package ‘assertthat’ successfully unpacked and MD5 sums checked
package ‘lazyeval’ successfully unpacked and MD5 sums checked
package ‘Rcpp’ successfully unpacked and MD5 sums checked
package ‘readr’ successfully unpacked and MD5 sums checked
package ‘hms’ successfully unpacked and MD5 sums checked
package ‘tibble’ successfully unpacked and MD5 sums checked
package ‘BH’ successfully unpacked and MD5 sums checked
package ‘haven’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\TEMP.HODENTEK9.000.001.002\AppData\Local\Temp\Rtmp84xjOn\downloaded_p

-----
Load the library
> library(haven)
-------------
I will try to read a file called 'employees.sav' which I downloaded to my laptop from internet here :

(https://www.spss-tutorials.com/spss-opening-data-with-syntax/).

Now I run this statment in R (Microsoft Client R.GUI)


Rlib_Haven_1

That's all folks!

No comments:

DMCA.com Protection Status