The `haven` package for `R`
Questions tagged [r-haven]
118 questions
0
votes
2 answers
How to read multiple large sas data files into R, filter rows and save subset datasets as .rds
I have 30 sas-files (dataset1.sas7bdat through dataset30.sas7bdat, approx. 10 GB per file) in a folder, and need to analyse a subset of rows in these data files (all rows where the character variable A begins with 10).
Thus, I need to read each of…
![](../../users/profiles/12222523.webp)
Aastedet
- 1
- 2
0
votes
0 answers
Error in df_parse_sav_file(spec, encoding, user_na): The file's timestamp string is invalid
When I try to read .sav file using Tidyverse package haven and it's function read_sav I get:
Invalid time string (length=8): 0: 0: 0
Error in df_parse_sav_file(spec, encoding, user_na):
The file's timestamp string is invalid.
However, if I use…
![](../../users/profiles/6326148.webp)
mihagazvoda
- 580
- 6
- 17
0
votes
0 answers
Convert character column to factor preserving column label
I have a dataframe that I read from the XLSX file. Every column name looks like this: CODE___DESCRIPTION so for example A1___Some funky column here. It is easier to use the codes as colnames but I want to use description when needed so it must be…
![](../../users/profiles/4959372.webp)
Matiasko
- 137
- 7
0
votes
1 answer
Select columns with a custom class
The question is very straightforward. I am using the haven package, which creates a custom class called haven_labelled when importing data from Stata into R (which has the benefit of displaying labels in R). I would like to select columns which have…
![](../../users/profiles/8071608.webp)
Tom
- 1,237
- 8
- 29
0
votes
1 answer
Haven package adding labels to stata data
I have a Stata data-set with 0,1 I am reading into R using
aa <- haven::read_dta("trial_data.dta")
table(aa$malpos)
Link to data
When its loaded in R the variable is comes in with 1,2 categories instead of 0,1. Is there a way I can avoid this?
![](../../users/profiles/1502106.webp)
Keniajin
- 1,499
- 2
- 20
- 38
0
votes
1 answer
Summary with label names with dplyr
I have imported a .sav file with Haven but where I am stuck is that I cant seem to work out how to print the label names in place or, with the label codings. Labels: 1 = unemployed, 2 = looking etc.
Employment <- select(well_being_df,…
![](../../users/profiles/10078592.webp)
psych.tek
- 25
- 4
0
votes
1 answer
Error reading sas metadata file through package haven R
I am using haven library to read SAS file metadata from a sas7bdat file. Following is the code used by me
library(haven)
sas_file <- read_sas("/dbfs/mnt/test1/Disease/Heart Attack/SAS/airline.sas7bdat",
catalog_file =…
![](../../users/profiles/4039616.webp)
Rahul Sharma
- 79
- 1
- 7
0
votes
1 answer
Read Stata value labels from a separate file into R
I have a Stata dataset (.dta file) that contains one variable, RGA (this is a MWE, I actually have tons of variables). This variable takes 3 factor values: 1, 2 and 3. These factors refer to meaningful things (so-called "value labels") and the…
![](../../users/profiles/5898008.webp)
Ben
- 167
- 2
- 10
0
votes
1 answer
How to work with labelled data from SPSS in R
This is a solution I found to work with labelled data from SPSS in R.
I'm working with a survey provided in SPSS and I moved from foreign to haven.
I read Convenient way to access variables label after importing Stata data with haven and I could not…
![](../../users/profiles/3720258.webp)
pachamaltese
- 2,702
- 4
- 24
- 48
0
votes
1 answer
R - Loss labels when I subset a data frame after using read_sav from haven package
I use the read_sav function from haven package to import an SPSS file. Therefore I have column names and associate labels (class labelled).
I lost the labels when I subset the data frame with subset. I can use a workaround with indexing data[i] but…
![](../../users/profiles/7100878.webp)
Kumpelka
- 749
- 2
- 10
- 27
0
votes
3 answers
want to avoid for loop in r and use one of the apply functions
Which apply function should be used to avoid the for loop in the code below? The variable labels are simple placeholders for now - the goal is to use this process for setting up a codebook in R for easy export to SPSS where the codebook is ready to…
![](../../users/profiles/6646805.webp)
Melinda Higgins
- 73
- 5
0
votes
1 answer
R package 'haven' read_spss: how to make it ignore value labels?
I have an SPSS file. I read it in using 'haven' package:
library(haven)
spss1 <- read_spss("SPSS_Example.sav")
I created a function that extracts the long labels (in SPSS - "Label"):
fix_labels <- function(x, TextIfMissing) {
val <- attr(x,…
![](../../users/profiles/2323534.webp)
user2323534
- 535
- 1
- 5
- 15
-1
votes
1 answer
How can I read .sas7bvew files in R?
I am looking for a package which can read .sas7bvew in R. I was trying with haven, but it can only read .sas7bdat
I tried the following: (assume lib2 contains the data.sas7bvew file, and I am trying to save it at lib1)
data lib1.mydata;
set…
![](../../users/profiles/10064285.webp)
Lotto7408
- 3
- 2