r - Dynamic counting of occurrences -
r newb. small rep of data. teamhome <- c("lal", "hou", "sas", "lal") teamaway <- c("ind", "sas", "lal", "hou") df <- data.frame(cbind(teamhome, teamaway)) df teamhome teamaway lal ind hou sas sas lal lal hou imagine these first 4 games of season thousands of games. home team , visitor team want compute cumulative number of games played @ home, on road , total. 3 new columns both home team , visiting team. (in case calculating new variables home team): teamhome teamaway hometeamgamesplayedathome hometeamgamesplayedroad hometeamtotalgames 1 lal ind 1 0 1 2 hou sas 1 0 1 3 sas lal 1 1 2 4 lal hou ...