-1
v1<-c(1,1,1,1,1,2,2,2,3,3,3,3,3,3,3)
v2<-c("Jan","Jan","Jan","Feb","Feb","Jan","Jan","Feb","Jan","Jan","Feb","Feb","Feb","Feb","Feb")
v3<-c("A1","E1","F1","B1","A1","E1","B1","C1","B1","D1","E1","A1","B1","C1","F1")
dt <- data.table(emp_id=v1,month=v2,work=v3)
我想將其轉換成一個數據幀/數據表,例如每work
由一個emp_id
完成佈置依次如dt
並且被存儲在一個載體,其進一步存儲在如下所示的列中。
我已經使用
dt1 <- dt[, .(work = list(work)), emp_id]
temp<-as.vector(dt1$work[3])
length(temp)
但結果是表示1。我想要這樣排序,它應該顯示結果3,因爲在第二行中有3個元素 - E1,B1,C1。
但是DT $工作分組不是矢量嗎? 'vv <-as.vector(dt1 $ work [2])'和 'length(vv)'然後顯示輸出爲1而不是3即(E1,B1,C1) – sid
@sid這是一個'list矢量''的''。你需要'is.vector(dt1 $ work [[2]])'' – akrun