I need to calculate the number of 4's and 6's a batsman has scored in a given cricket database.
The following is my code:
runs_batsman = ballbyball[,c("Batter","RunsBatsman")]
fours = data.frame(bat_name)
numoffours = function(name)
{counter = 0
for(i in nrow(ballbyball))
{
if((identical(toString(name),toString(runs_batsman[i,1]))))
{
if(runs_batsman[i,2]== 4)
{
counter = (counter + 1)
}
}
}
return(counter)
}
summary = function(dataset){
fours[,"numfours"]=0
for (j in nrow(bat_name)){
fours[j,2] = lapply(bat_name[j,1], numoffours)
}
return(fours)
}
I am not getting any values for any of the batsmen. bat_name
is the data frame with all batsmen names. Please help me.
I am very new to R
so please explain in much detail as possible.