[英]Rescale for NBA heatmap: dplyr equivalent to plyr function?
There is this great example of how to use ggplot2 to create a heat map the 'R; 有一个很好的例子,说明如何使用ggplot2创建热图'R; way: Rheatmap which provides a link to the raw data and the source code.
方式: Rheatmap ,提供指向原始数据和源代码的链接。
There was a followup using ggplot2: ggplot2 which lays out the ggplot2 code. 使用ggplot2进行了跟进: ggplot2 ,它布置了ggplot2代码。
At key points the ggplot2 code uses reshape2 and plyr. 在关键点,ggplot2代码使用reshape2和plyr。
nba.m <- melt(nba)
nba.m <- ddply(nba.m, .(variable), transform,rescale = rescale(value))
My goal is to duplicate these calculations using tidyr and dplyr. 我的目标是使用tidyr和dplyr重复这些计算。
nba.m <- melt(nba)
has a tidyr equivalent in: 在以下方面有类似的tidyr:
nba.g <- gather(nba, Name)
What is the dplyr equivalent to this line? dplyr等于这行是什么?
nba.m <- ddply(nba.m, .(variable), transform,rescale = rescale(value))
eipi10 kindly suggested eipi10建议
nba.m2 <- nba.m %>%group_by(Name) %>% mutate(rescale=rescale(value))
However, it looks like the rescale calculation is not occuring in quite the 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 is missing? 什么东西少了?
Thanks, Matt 谢谢,马特
I think you need write dplyr::mutate
, not mutate
. 我认为您需要写
dplyr::mutate
,而不是mutate
。
I presume you loaded plyr
and dplyr
in the same session. 我假设您在同一会话中加载了
plyr
和dplyr
。 dplyr
and plyr
are conflict the following objects: arrange, count, desc, failwith, id, mutate, rename, summarise, summarize
dplyr
和plyr
与以下对象冲突: arrange, count, desc, failwith, id, mutate, rename, summarise, summarize
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.