I have put the new variable at the beginning and trimed the output to 10 rows just for illustration purposes, so it can be shown properly on a post.
You can omit those lines and get the same result as with your code.
Thanks. I’ve used your code to create two variables, asq_light and ask_heavy, however, the length of the dataset didn’t change. Are these "virtual variables"?
Are you assigning the output to a variable?
Remember that dplyr
doesn't perform in-place modifications.
new_data <- data2 %>%
mutate_at(vars(starts_with("asq_")), as.numeric) %>%
rowwise() %>%
mutate(asq_light = mean(c(asq_1a, asq_2a, asq_3a, asq_4a, asq_5a,
asq_6a, asq_7a, asq_8a, asq_9a), na.rm = TRUE)) %>%
ungroup()
Ah, ok. As a complete newbie, I didn’t know that about dplyr.
I asked about saving the variable because I don't know how to use it otherwise. I tried accessing it from the console but got an error message.
> asq_light
Error: object 'asq_light' not found
> data2$asq_light
NULL
Warning message:
Unknown or uninitialised column: 'asq_light'.
Thanks for helping me. I really appreciate your time and assistance.
Cheers,
Jason
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.