在R中计算获胜次数和平均主队获胜几率 [英] Count Wins and Average Home Win Odds in R

查看:96
本文介绍了在R中计算获胜次数和平均主队获胜几率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在R中创建一个数据框,使我能够查看每个团队的平均主场赔率以及每个赛季的主场获胜次数.

I'm trying to create a data frame in R that will allow me to view the average home betting odds for each team along with the number of home wins for each season.

数据集中有6,840条记录,代表了18个赛季的英超联赛.这意味着每个赛季有380个比赛条目.

There are 6,840 records in the dataset representing 18 seasons' worth of Premier League football. This means there are 380 match entries for each season.

让我给你看一个例子.这是一个大幅削减的示例,但它为您提供了有关我要实现的目标的足够好的想法.

Let me show you an example. It is a drastically cut down example, but it gives you a good enough idea about what I'm trying to achieve.

键:FTHG(全场主进球),FTAG(全场客球),FTR(全场结果),HWO(主场获胜赔率),AHWO(平均主场获胜赔率),W(获胜次数) )

Key: FTHG (Full-Time Home Goals), FTAG (Full-Time Away Goals), FTR (Full-Time Result), HWO (Home Win Odds), AHWO (Average Home Win Odds), W (Win Count)

matchData:

matchData:

       Season   | HomeTeam | AwayTeam | FTHG | FTAG | FTR | HWO
-----------------------------------------------------------------
1  |  2017/2018 |  TeamA   |  TeamB   |   2  |   1  |  H  | 1.30
2  |  2017/2018 |  TeamA   |  TeamC   |   1  |   1  |  D  | 1.45
3  |  2017/2018 |  TeamA   |  TeamD   |   1  |   0  |  H  | 2.20
4  |  2017/2018 |  TeamB   |  TeamA   |   4  |   1  |  H  | 1.85
5  |  2017/2018 |  TeamC   |  TeamA   |   1  |   0  |  H  | 1.70
6  |  2017/2018 |  TeamD   |  TeamA   |   2  |   3  |  A  | 3.10
7  |  2016/2017 |  TeamA   |  TeamB   |   2  |   1  |  H  | 1.30
8  |  2016/2017 |  TeamA   |  TeamC   |   0  |   0  |  D  | 1.50
9  |  2016/2017 |  TeamA   |  TeamD   |   1  |   2  |  A  | 1.67
10 |  2016/2017 |  TeamB   |  TeamA   |   3  |   1  |  H  | 1.42
11 |  2016/2017 |  TeamB   |  TeamC   |   2  |   1  |  H  | 1.90
12 |  2016/2017 |  TeamB   |  TeamD   |   5  |   1  |  H  | 1.20
13 |  2016/2017 |  TeamC   |  TeamA   |   1  |   0  |  H  | 2.00
14 |  2016/2017 |  TeamC   |  TeamB   |   3  |   1  |  H  | 1.80

我需要将matchData数据框架总结为一个新的框架,如下所示:

I need to summarise the matchData data frame into a new one like this:

homeWinOdds:

homeWinOdds:

       Season   |   Team  | W | AHWO
-------------------------------------
1  |  2017/2018 |  TeamA  | 2 | 1.75
2  |  2017/2018 |  TeamB  | 1 | 1.85
3  |  2017/2018 |  TeamC  | 1 | 1.70
4  |  2017/2018 |  TeamD  | 0 | 3.10
5  |  2016/2017 |  TeamA  | 1 | 1.49
6  |  2016/2017 |  TeamB  | 3 | 1.51
7  |  2016/2017 |  TeamC  | 2 | 1.90
8  |  2016/2017 |  TeamD  | 0 | N/A 

例如,基于以上所述,TeamB在2016/2017赛季赢得了三场主场比赛,他们的平均主场赔率(基于该赛季主场比赛的所有所有)为1.51.

For instance, based on the above, TeamB won three home matches in season 2016/2017 and their average home odds (based on all of their home matches in that season) were 1.51.

在我的实际数据集中,每队20支球队中的每支球队每个赛季都将打满19场主场比赛,因此这些比赛的主场赔率将平均.

In my actual dataset, each one of the 20 teams will have each played exactly 19 home matches in every season, so the home odds of these matches will be averaged.

总结:

  • 计算一支球队在一个赛季中获得的主场胜利次数
  • 平均整个赛季的主场获胜赔率(仅针对球队的主场比赛)
  • 显示为单独的记录-在实际数据集中,每个赛季有20支球队,因此每个赛季将有20条记录.

在此先感谢任何可以帮助我的人.

I appreciate in advance anyone who can help me with this.

推荐答案

library(dplyr)
homeWinOdds <- matchData %>% 
  group_by(Season, HomeTeam) %>% 
  summarize(W    = sum(FTR == "H"), 
            AHWO = mean(HWO)) %>%
  ungroup()

这篇关于在R中计算获胜次数和平均主队获胜几率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆