Questions tagged [r-haven]

Use this tag for questions related to the `haven` package for the R programming language. The `haven` package "enables R to read and write various data formats used by other statistical packages". For more information on the `haven` package see the [package website](https://haven.tidyverse.org/index.html).

159 questions
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…
Tom
  • 2,173
  • 1
  • 17
  • 44
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?
Keniajin
  • 1,649
  • 2
  • 20
  • 43
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,…
psych.tek
  • 25
  • 5
0
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…
Lotto7408
  • 13
  • 2
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 =…
Rahul Sharma
  • 89
  • 1
  • 2
  • 9
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…
Ben
  • 429
  • 4
  • 11
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…
Kumpelka
  • 869
  • 3
  • 11
  • 33
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…
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,…
user2323534
  • 585
  • 1
  • 6
  • 18
1 2 3
10
11