This Learning R post applies a function to a column based on variable group:
The data looks like this:
NAME, variable, value
1 , GROUP1, 10
2 , GROUP1, 20
3 , GROUP2, 20
4 , GROUP2, 30
I can use this function to rescale by variable:
nba.m <- ddply(nba.m, .(variable), transform, rescale = rescale(value))
How would I perform this same calculation using the dplyr package? I've tried:
nba.m <- nba.m %>%group_by(variable) %>% mutate(rescale=rescale(as.numeric(value)))
However this scales the entire "value" column without grouping by variable. Thanks, Matt
dplyr::mutate(rescale=
– akrunrescale()
come from? It seems to work fine with scale:nba.m %>%group_by(variable) %>% mutate(rescale=scale(as.numeric(value)))
What output do you get? Do you have bothdplyr
andplyr
loaded? Did you loadplyr
first? – MrFlickggplot2
, some hadleyverse "scales" package is loaded which has arescale
function; I guess that's it. Must be, sinceggplot2
is in the title of the post the OP linked to – Frank