且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

R和dplyr:创建一个新列,该列将值除以另一列的多个最大值

更新时间:2023-01-20 20:52:02

如果需要创建列(通过将每个'id'的反应时间('rt')除以最大反应时间( max(rt,na.rm = TRUE)),那么我们需要按'id'分组并进行除法。

If we need to create a column ('spcRT') by dividing the reaction time ('rt') with the maximum reaction time (max(rt, na.rm=TRUE)) for each 'id', then we need to group by 'id' and do the division.

 df %>%
    group_by(id) %>%
    mutate(spcRT = rt/max(rt, na.rm=TRUE))






尚不清楚为什么OP在帖子中使用 rt和 id作为分组变量。这样只会提供一个唯一的 rt值,不需要任何 max