全日空

Beginner tips on using plyr to calculate year-over-year change across groups

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am new to plyr (and R) and looking for a little help to get started. Using the baseball dataset as an exaple, how could I calculate the year-over-year (yoy) change in "at batts" by league and team (lg and team)? library(plyr) df1 After doing a little aggregating to simplify the data fame, the data looks like this: head(df1) year lg team ab 1884 UA ALT 108 1997 AL ANA 1703 1998 AL ANA 1502 1999 AL ANA 660 2000 AL ANA 85 2001 AL ANA 219 I would like to end up with someting like this year lg team ab yoy 1997 AL ANA 1703 NA 1998 AL ANA 1502