Enable numeric responses with value labels from `fetch_survey()`
#363 opened on Feb 13, 2025
Repository metrics
- Stars
- (229 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
I recently discovered this package and think it's awesome. However, there is one significant downside to using this compared to downloading the data directly from Qualtrics.
I tend to download my data via the SPSS option so that each variable has both the label and labels attributes. This makes it easy to convert numeric variables to factors via the labels attribute but also to calculate means with the numeric vector.
I have tried almost all of the arguments in fetch_survey() trying to get this but none of them add the labels attribute to the variables. Having the option of downloading the data where each variable has value labels (labels attribute) would be incredibly valuable.
While I'm not at all familiar with the API, I would assume that there I some way of accessing the data from Qualtrics in the SPSS style instead of csv.
Nevertheless, this how I'd like the data set up with value labels:
ideal_df <- data.frame(
a = c(3, 4, 4, 4, 1, 2, 3, 1) %>%
structure(
label = "Variable A as numeric with value labels",
labels = c("Strongly agree" = 1, "Somewhat agree" = 2, "Somewhat disagree" = 3, "Strongly disagree" = 4)
),
b = c(1, 1, 2, 2, 1, 3, 3, 4) %>%
structure(
label = "Variable B as numeric with value labels",
labels = c("Strongly agree" = 1, "Somewhat agree" = 2, "Somewhat disagree" = 3, "Strongly disagree" = 4)
)
)
Now here are the kinds of data sets you get from fetch_survey()
# a data set that you get when the `label` argument is FALSE
label_TRUE <- data.frame(
a = c("Somewhat disagree", "Strongly disagree", "Strongly disagree", "Strongly disagree", "Strongly agree", "Somewhat agree", "Somewhat disagree", "Strongly agree") %>%
structure(label = "Variable A as a character vector"),
b = c("Strongly agree", "Strongly agree", "Somewhat agree", "Somewhat agree", "Strongly agree", "Somewhat disagree", "Somewhat disagree", "Strongly disagree") %>%
structure(label = "Variable b as a character vector")
)
# a data set that you get when the `label` argument is FALSE
label_FALSE <- data.frame(
a = c(3, 4, 4, 4, 1, 2, 3, 1) %>%
structure(
label = "Variable A as numeric without value label",
),
b = c(1, 1, 2, 2, 1, 3, 3, 4) %>%
structure(
label = "Variable B as numeric without value label",
)
)