r - Rescale for NBA heatmap: dplyr equivalent to plyr function? -


there great example of how use ggplot2 create heat map 'r; way: rheatmap provides link raw data , source code.

there followup using ggplot2: ggplot2 lays out ggplot2 code.

at key points ggplot2 code uses reshape2 , plyr.

nba.m <- melt(nba) nba.m <- ddply(nba.m, .(variable), transform,rescale = rescale(value)) 

my goal duplicate these calculations using tidyr , dplyr.

 nba.m <- melt(nba) 

has tidyr equivalent in:

 nba.g <- gather(nba, name)  

what dplyr equivalent line?

nba.m <- ddply(nba.m, .(variable), transform,rescale = rescale(value)) 

eipi10 kindly suggested

nba.m2 <- nba.m %>%group_by(name) %>% mutate(rescale=rescale(value)) 

however, looks rescale calculation not occuring in quite same way:

> head(nba.m)         name variable value   rescale 1   dwyane wade         g    79 0.9473684 2  lebron james         g    81 0.9824561 3   kobe bryant         g    82 1.0000000 4 dirk nowitzki         g    81 0.9824561 5 danny granger         g    67 0.7368421 6  kevin durant         g    74 0.8596491 > head(nba.m2) source: local data frame [6 x 4] groups: name          name name.1 value   rescale 1   dwyane wade       g    79 0.9634146 2  lebron james       g    81 0.9878049 3   kobe bryant       g    82 1.0000000 4 dirk nowitzki       g    81 0.9878049 5 danny granger       g    67 0.8170732 6  kevin durant       g    74 0.9024390 >  

what missing?

thanks, matt

i think need write dplyr::mutate, not mutate.

i presume loaded plyr , dplyr in same session. dplyr , plyr conflict following objects: arrange, count, desc, failwith, id, mutate, rename, summarise, summarize


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -