23743

Importing values and labels from SPSS with memisc

Question:

I want to import both values and labels from a dataset but I don't understand how to do it with this package (the documentation is not clear). I know it is possible because <a href="http://cran.r-project.org/web/packages/Rz/index.html" rel="nofollow">Rz</a> (a gui interface for R) uses memisc to do this. I prefer, though, not to depend on too many packages.

Here the only piece of code I have:

dataset <- spss.system.file("file.sav")

Answer1:

See the example in ?importer() which covers spss.system.file().

spss.system.file creates an 'importer' object that can show you variable names.

To actually use the data, you need to either do:

## To get the whole file dataset2 <- as.data.set(dataset) ## To get selected variables dataset2 <- subset(dataset, select=c(variable names)) to get selected variables.

You end up with a data.set object which is quite complex, but does have what you want. For analysis, you usually need to do: as.data.frame on dataset2.

Answer2:

I figured out a solution to this that I like

df <- suppressWarnings(read.spss("C:/Users/yada/yada/yada/ - SPSS_File.sav", to.data.frame = TRUE, use.value.labels = TRUE)) var_labels <- attr(df, "variable.labels") names <- data.frame(column = 1:ncol(df), names(df), labels = var_labels, row.names=NULL) names(df) <- names$labels names(df) <- make.names(df))

Recommend

  • How to use lateral view explode in Hive for XML data format?
  • Attributes/information contained in DataFrame column names
  • Java : How to tint this PNG programmatically?
  • How to repeat sections of a SQL query across UNIONs? (DRY in SQL)
  • C++ cout and enum representations
  • pillow imaging ImportError
  • Problems installing Yesod for Haskell
  • error importing numpy
  • Updating server-side rendering client-side
  • Cross-Platform Protobuf Serialization
  • javascript inside java/jsp code
  • Sending data from AppleScript to FileMaker records
  • htaccess rewriting URLs with multiple forward slashes
  • Weird JavaScript statement, what does it mean?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • How do you troubleshoot character encoding problems?
  • Matplotlib draw Spline from multiple points
  • AT Commands to Send SMS not working in Windows 8.1
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • How to format a variable of double type
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper folder structure for lots of source files
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Benchmarking RAM performance - UWP and C#
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Acquiring multiple attributes from .xml file in c#
  • coudnt use logback because of log4j
  • How do I configure my settings file to work with unit tests?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How does Linux kernel interrupt the application?
  • How can I remove ASP.NET Designer.cs files?
  • Is it possible to post an object from jquery to bottle.py?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal