1

If I have a dataframe with match results (3 possible values) and probabilities, for example:

FTR     Probability
H       0.49
A       0.35
H       0.21
D       0.71
D       0.19
...

And I want for each possible value of Probability to count the total no' of some FTR value. lets say H. So I guess I should run a for loop that will run for every unique value of Probability and count the number of H in that group.

I tried doing that by writing: for (i in 1:unique(dataframe$Probability)) { count(group_by(dataframe, FTR)) } which doesn't work because I guess the problem starts with unique cuz it can not run through actual values of probability but their index value.

bm1125
  • 223
  • 1
  • 10

1 Answers1

2

let's say for data.frame is mydf

mydf <- data.frame(stringsAsFactors=FALSE,
           FTR = c("H", "A", "H", "D", "D"),
   Probability = c(0.49, 0.35, 0.21, 0.71, 0.19)
)

with(mydf, table(Probability, FTR))

will get you this

           FTR
Probability A D H
       0.19 0 1 0
       0.21 0 0 1
       0.35 1 0 0
       0.49 0 0 1
       0.71 0 1 0
Selcuk Akbas
  • 711
  • 1
  • 8
  • 20