Add variable to table

I am trying to add the team winning percentage into Teams2015 but am unsure how to do so. The calculation is WinPercent = W/(W+L). How would I add this to the code below?

Teams2015 <- Teams %>%
select(yearID, teamID, name, G, W, L,attendance) %>%
filter(yearID >= 2015) %>%
mutate(teamID = droplevels(teamID)

Without seeing the data, my guess is that you want code like the following.

Teams2015 <- Teams %>%
select(yearID, teamID, name, G, W, L,attendance) %>%
filter(yearID >= 2015) %>%
mutate(teamID = droplevels(teamID),
       Win_Perc = W/(W + L))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.