Write DataFrame to SPSS .sav File in R
Last Updated :
14 Sep, 2021
In this article, we are going to see how to write Dataframe to SPSS .sav File in R Programming language. The SPSS Statistics File Format is a proprietary binary format, developed and maintained as the native format for the SPSS statistical software application. To write a data frame in SPSS format in R we use the write_sav() function of the haven package in R.
Syntax: write_sav(Data,”Filename.sav”)
Parameters:
- Data: Dataframe that is been exported
- Filename.sav: Filename where exported dataframe will be stored
Writing dataframe to SPSS .sav file
Here we are going to use the haven package, which is used to read write various data formats.
R
Demo <- data.frame (Batch = c (2017, 2018, 2019, 2020, 2021),
Students = c (2300, 1200, 3500, 1400, 120),
Class = c ( "DSA Essential" , "Placement100" ,
"C++: Expert" ,
"Web Development Bootcamp" ,
"Android Development Bootcamp" ))
library ( "haven" )
write_sav (Demo, "SPSS.sav" )
|
Output:
After running the code, we see a new file SPSSS.sav in your working directory.
Working directory
We can see data in SPSS.sav file using the following code:
Output
Share your thoughts in the comments
Please Login to comment...