-1
我有DF <-(ID,Year,Sales)
,我想創建第四列LastYearSale
,選擇去年的銷售額。例如,如果有:去年同日銷售
ID Year Sales
1 01/01/2015 50000
2 01/01/2014 20000
我想輸出是這樣的:
ID Year Sales LastYearSales
1 01/01/2015 50000 20000
2 01/01/2014 20000
試試'library(dplyr); DF%>%mutate(LastYearSales = lead(Sales))' – akrun