我怎么能根据列A的字符串值从列B中减去一个值

huangapple go评论53阅读模式
英文:

How can I subtract a value from a column B based upon a string value of column A

问题

我想要创建另一列(novig_new),其中包含 Pinnacle 书maker 的 novig_prob 值减去其他书maker 对每支球队的值。这是我的 tibble:

我怎么能根据列A的字符串值从列B中减去一个值

这是我想要实现的目标。

我怎么能根据列A的字符串值从列B中减去一个值

英文:

I would like to create another column (novig_new) which contains the value of the Pinnacle bookmaker's novig_prob subtracted from the other bookmakers for each team. Here is my tibble:

我怎么能根据列A的字符串值从列B中减去一个值

This is what I am looking to accomplish.

我怎么能根据列A的字符串值从列B中减去一个值

答案1

得分: 1

或许,我们可能需要

library(dplyr)
df1 %>%
   group_by(team) %>%
   mutate(novig_new = novig_prob - novig_prob[match("Pinnacle", bookmaker)]) %>%
   ungroup
英文:

Perhaps, we may need

library(dplyr)
df1 %>%
   group_by(team) %>%
   mutate(novig_new = novig_prob - novig_prob[match("Pinnacle", bookmaker)]) %>%
  ungroup

huangapple
  • 本文由 发表于 2023年2月6日 05:51:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定