Write Data Frame to SPSS .sav File in R (Example)

 

In this R programming tutorial you’ll learn how to save a data frame to an SPSS .sav file.

Table of contents:

Here’s the step-by-step process:

 

Creation of Example Data

We’ll use the following data as basement for this R tutorial:

data <- data.frame(x1 = 3:7,    # Create example data
                   x2 = letters[3:7],
                   x3 = 0)
data                            # Print example data

 

table 1 data frame write data frame as spss sav file r

 

As you can see based on Table 1, our example data is a data frame consisting of five rows and three columns.

 

Example: Export Data Frame as SPSS .sav File Using write_sav Function of haven Package

The R programming syntax below illustrates how to write our example data frame to an external .sav file on our computer.

For this, we first need to install and load the haven package:

install.packages("haven")       # Install & load haven
library("haven")

Next, we can use the write_sav function of the haven package to store our data frame in a .sav file:

write_sav(data, "data.sav")     # Apply write_sav function

Have a look at the working directory you are currently using. After running the previous R code, it should contain an SPSS .sav file called data.sav.

 

Video & Further Resources

Do you want to learn more about exporting data from R? Then I can recommend having a look at the following video of my YouTube channel. I show the R codes of this tutorial in the video.

 

The YouTube video will be added soon.

 

Also, you could have a look at some of the related tutorials of my website. I have published several articles on topics such as data types, exporting data, and variables.

 

In this article, I have illustrated how to write a data frame to an SPSS .sav file in the R programming language. Let me know in the comments below, if you have further questions and/or comments. Furthermore, don’t forget to subscribe to my email newsletter to get updates on the newest articles.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Top