-
Notifications
You must be signed in to change notification settings - Fork 3
Unnesting questionnaire data #7
Copy link
Copy link
Open
Labels
Description
Hi there,
We are switching over to use this new R package to interact with the data API.
I wanted to share a function that our team has used for ages in order to unnest the data in the Questionnaire for cases (and I think in some other places as well). We found the nested data difficult to work with and having a function to "extract" the data and put it in it's own column directly was super helpful.
I just wanted to share it in case it might be useful to others.
(This could probably be improved; it did what we needed so I moved on.)
GDextract <- function(x, var_to_extract, extracted_var_name) {
for (lv in 1:nrow(x)) {
if (is.null(unlist(
x[[lv, var_to_extract]])
) == FALSE) {
x[[lv, extracted_var_name]] <-
unlist(
x[[lv, var_to_extract]]
)} else {
x[[lv, extracted_var_name]] <- as.character(NA)
}
}
return(x)
}
If this is no use to anyone, please feel free to close or delete or whatever. :)
Luke
Reactions are currently unavailable