Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: read_string for self-documenting survey responses #1567

Open
higgi13425 opened this issue Dec 12, 2024 · 0 comments
Open

feature request: read_string for self-documenting survey responses #1567

higgi13425 opened this issue Dec 12, 2024 · 0 comments

Comments

@higgi13425
Copy link

higgi13425 commented Dec 12, 2024

Survey responses are often encoded both as a number (0,1,2,3) and as a response string (None, mild, moderate, severe).

Data mishaps often occur when people analyzing the data mix up which number is associated with each response
This can be really embarrassing when you mix up things like male/female or
responded/did not respond, and you make the wrong conclusion in your data analysis.

In a perfect world, we would all refer to the codebook every time we needed to,
but humans are a bit lazy, and
we often wing it (or assume we know the encoding)

It can be really helpful to store the survey responses as self-encoding data, where the numbers are linked to the responses,
with a single intervening underscore,
like "0_None", "1_Mild", "2_Moderate", "3_Severe", or
"0_Alive", "1_Dead",
or "1_Male", "2_Female"

So that you don't need to look at the codebook, and you won't make silly mistakes

These work well as character variables, or (even better) stored as ordered factors.
But sometimes it is helpful to be able to

  1. extract the number - parse_number() already does this, and is fabulous
  2. extract the string (response) - parse_character() does not extract the response - it returns all characters, which is reasonable.
  • but it would be really nice to have something like parse_string() to extract
  • "None", "Mild", "Moderate", "Severe"
    without the numbers or underscores (like parse_number() does for numbers)

These are nice for labels in tables or in categorical plots


I propose using the function:

parse_string <- function(value) {
    str_extract(string = value, 
    pattern = "(?<=\\d\\_).+")
  # to extract the response string portion from NN_ResponseString
}
@higgi13425 higgi13425 changed the title feature request: read_string or for self-documenting survey responses feature request: read_string for self-documenting survey responses Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant