Questions tagged [r-labelled]

19 questions
2
votes
0 answers

Conflict between DT::datatable and haven_labelled

There seems to be a conflict between DT::datatable and haven_labelled data types. This works fine: library(dplyr) library(DT) library(labelled) testDf <- tibble(a=c("one","two"), b=c(1,2)) datatable(testDf) This does not: test2Df…
bcarothers
  • 824
  • 8
  • 19
2
votes
3 answers

Create column with labels from labelled data

I have a data set with labelled data and would like to create a new column containing only the label as character. Consider the following example: value_labels <- tibble(value = 1:6, labels = paste0("value", 1:6)) df_data <- tibble(id = 1:10, var =…
Ivo
  • 3,890
  • 5
  • 22
  • 53
1
vote
1 answer

using purrr::pmap() to assign data frame column labels

I was trying to assign labels to columns of multiple data frames. I have more than 10 data frames I wanted to manipulate but here are some examples: df1 = tribble( ~a_age, ~a01edu, ~other_vars, 35, 17, 1, 41, 14, 2, 28, 12, 3, 68, 99,…
nightstand
  • 329
  • 2
  • 11
1
vote
1 answer

plm::pdata.frame loses variable label attributes created by labelled::var_label?

I have a panel data to which I have applied plm::pdata.frame to be able to use the lag operator. However, once I have converted by dataframe to pdata.frame, the variable labels that I created using labelled::var_label do not show up in…
Anup
  • 239
  • 2
  • 11
1
vote
1 answer

How to tag all missing values of an SPSS labelled dataframe by their label?

I have labeled SPSS data like this: library(labelled) library(tidyverse) test <- tibble( var_1 = labelled_spss( c(1:4, 89,999), c(Terrible = 1, Meh = 2, Better = 3, Awesome = 4, dk = 89, "does not apply" = 999) ), var_2 =…
Tea Tree
  • 882
  • 11
  • 26
1
vote
0 answers

Losing variable label after certain changes to variable inside mutate

This is similar to the question "Losing all variable labels when mutating a column" from a few months ago. Depending on what type of change you do inside of a mutate to the variable in question, you'll either lose or not lose the variable's…
1
vote
2 answers

Change multiple value labels using tidyverse syntax?

The labelled package provides this functionality to modify value labels for multiple variables in one go: df <- data.frame(v1 = 1:3, v2 = c(2, 3, 1), v3 = 3:1) val_labels(df[, c("v1", "v3")]) <- c(YES = 1, MAYBE = 2, NO = 3) val_labels(df) But I'm…
spindoctor
  • 1,719
  • 1
  • 18
  • 42
1
vote
0 answers

Labelled R-Dataset and Import to SPSS

I would like to change a dataset I landed in RStudio (R-4.1.1) to a sav-file. For this I want to label the variables with the function labelled from the package 'labelled' accordingly, i.e. with variables label and variables description. The problem…
FuncAna09
  • 23
  • 3
1
vote
1 answer

How do I create a loop to change the text encoding of the labels in labelled variables in R

I have imported a stata file that is giving me some encoding problems in the value labels. On import, using labelled::lookfor for any keyword returns this error: Error in structure(as.character(x), names = names(x)) : invalid multibyte string at…
spindoctor
  • 1,719
  • 1
  • 18
  • 42
1
vote
0 answers

Losing all variable labels when mutating a column

I uploaded an .sav file using haven. df <- read_sav("file.sav", user_na = FALSE) This makes sure that all the metadata including the labels are imported into r. However, after running all my code (mutations etc.), I notice that all variables that…
Victor Nielsen
  • 443
  • 2
  • 14
1
vote
1 answer

How to adjust encoding to read accent marks properly in R

I am using read_labelled_csv from expss package to read a labelled csv in R. data1<-expss::read_labelled_csv("C:/Users/User/Desktop/Data/Example.csv") I have a problem reading the labels that has accents. The label looks like this: caf˳ and it has…
0
votes
1 answer

import all SAS files in folder and convert labels to column names in R

Following on from post (How to write efficient code for importing multiple SAS files) I have used the below to load all SAS files into an R dataframe/tibble, however the label names are lost in unnest() step. How can one perform operations on the…
JMonk
  • 71
  • 5
0
votes
1 answer

Turning SPSS chr+label variables into labelled factors in R

I cannot reproduce this example I have an SPSS dataset with chr + label variables which I have converted to an R object using the read_sav() function from the haven package. When I call their structure via str(foo) they look like this #' chr+lbl…
llewmills
  • 2,959
  • 3
  • 31
  • 58
0
votes
0 answers

Is there a way to view data in RStudio data viewer and have labelled vectors showing value labels?

I am using data in the form of a tibble with almost entirely categorical factors, each containing value labels for each factor levels. I would like to convert one of my factors to a labelled vector using the haven::labelled() command with value…
0
votes
0 answers

R function for labeling the beginning and the end of a stacked bar

I am trying to make a stacked bar with the beginning and ending labels for each stacked element. my code is this: ggplot(chr2007816root, aes(fill=factor(Feature,levels = c("tnt1","ex6", "int5", "ex5", "int4", "ex4", "int3", "ex3",…
1
2