3
組,我想按組「會議」縮放選擇的變量data.table:規模在data.table
session score1 score2
1: 1 0.11111111 0.6000000
2: 1 0.00000000 0.5333333
3: 1 0.27777778 0.6666667
4: 1 0.66666667 0.8666667
5: 1 0.83333333 1.0000000
6: 2 0.07692308 0.5757576
7: 2 0.25641026 0.6363636
8: 2 0.00000000 0.5303030
9: 2 0.64102564 0.7878788
10: 2 0.84615385 1.0000000
我已經試過:
dt[,(2:3):=lapply(.SD,scale),by="session",.SDcols=2:3]
但我得到一個錯誤:
Error in `[.data.table`(dt, , `:=`((2:3), lapply(.SD, scale)), by = "session", :
All items in j=list(...) should be atomic vectors or lists. If you are trying something like j=list(.SD,newcol=mean(colA)) then use := by group instead (much quicker), or cbind or merge afterwards.
代碼工作,但只是沒了分組變量(會話)。我究竟做錯了什麼?