我有一个 2200 万个观察行的数据表,其形式如下:
`dt <- data.table(
firm_id = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
metric = c("AN_BILANT", "OPEX", "CAPEX","AN_BILANT","OPEX", "CAPEX", "AN_BILANT", "OPEX", "CAPEX", "AN_BILANT","OPEX", "CAPEX"),
value = c(2013, 10, 3,2014, 11, 5, 2007, 25, 10, 2009, 23, 7)
)`
Run Code Online (Sandbox Code Playgroud)
我想使用 data.table 生成以下输出
`output_dt <- data.table(
firm_id = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2),
metric = c("OPEX", "CAPEX","OPEX", "CAPEX", "OPEX", "CAPEX", "OPEX", "CAPEX"),
AN_BILANT = c(2013, 2013, 2014, 2014, …Run Code Online (Sandbox Code Playgroud)