更新时间:2023-02-22 13:09:31
您可以使用 data.table
dcast
> You can use dcast
from data.table
library(data.table)
dcast(dT, A + B + ID ~ paste0("E", rowid(ID)))
# A B ID E1 E2 E3
#1 a1 b1 1 0.4069439 0.3526222 0.2337894
#2 a1 b2 3 0.6211421 0.3943915 0.5505793
#3 a2 b2 4 0.7421095 0.7796073 0.6906605
您需要先创建正确的时间变量,即 rowid( ID)
。
You need to create the correct 'time variable' first which is what rowid(ID)
does.