将平均值添加到数据框

时间:2020-08-23 04:10:45

标签: r

我正在从事与棒球相关的项目,我从每个球场的数据中获取每个球员的统计wOBA平均值。我想将这些平均值添加到按间距数据帧的原始间距中,但是唯一的问题是,第一个数据帧上每个玩家ID都有多个,因此我无法弄清楚如何将平均值附加到每个ID。这是我正在查看的示例:

平均数据帧:

        batterID  wOBA
  {1}   84621     .321
  {2}   95480     .296

逐个间距数据帧:

        batterID  AB  wOBA average
  {1}   84621     1   (put his average wOBA here)
  {2}   84621     2   (put his average wOBA here)
  {3}   84621     3   (put his average wOBA here)
  {4}   95480     1   (put his average wOBA here)
  {5}   95480     2   (put his average wOBA here)
  {6}   95480     3   (put his average wOBA here)

我尝试了对其进行突变,但是由于数据帧具有不同数量的列,因此无法正常工作。我在这里可以做什么?

0 个答案:

没有答案