You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All of the dplyr functions make R code more readable except for one pretty common case, conditionally assigning variable values with mutate(). The current syntax is something like: df <- mutate(df, newvar = ifelse(oldvar %in% c("a", "b", "c"), "group1", ifelse(oldvar %in% c("d", "e", "f"), "group2", ifelse(oldvar %in% c("g", "h", "i"), "group3", NA))))
All of the dplyr functions make R code more readable except for one pretty common case, conditionally assigning variable values with mutate(). The current syntax is something like:
df <- mutate(df, newvar = ifelse(oldvar %in% c("a", "b", "c"), "group1", ifelse(oldvar %in% c("d", "e", "f"), "group2", ifelse(oldvar %in% c("g", "h", "i"), "group3", NA))))
I saw a question on StackOverflow that gave a much better solution, borrowing from the "mosaic" package: http://stackoverflow.com/questions/24459752/can-dplyr-package-be-used-for-conditional-mutating?rq=1
Could something like this be the default syntax, please?
Data frame for testing:
df <- data.frame(oldvar = letters)
The text was updated successfully, but these errors were encountered: