如何计算数据框“ match_outcome”的获胜百分比

时间:2019-04-06 23:02:18

标签: r

大家好,我是几周前才刚开始的,如果这很简单,请对不起。

我有一个数据框,其中的一列称为“ game_outcome”。这些行是“赢”或“亏损”。我想计算获胜的百分比

1 个答案:

答案 0 :(得分:0)

方法很多,这里有几种方法

# sample data frame
df = data.frame(game_outcome=sample(c("win", "lose"), 100, replace = T), a=1, b=NA)

# get counts for each category and find proportion
table(df$game_outcome) / nrow(df)

lose  win 
0.53 0.47 

# for only one case
sum(df$game_outcome == "win") / nrow(df)

0.47
相关问题