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)
I want to convert it into a dataframe/datatable such every work
done by one emp_id
is arranged sequentially as in the dt
and is stored in a vector which is further stored in a column as shown below.
I have used
dt1 <- dt[, .(work = list(work)), emp_id]
temp<-as.vector(dt1$work[3])
length(temp)
But the result is showing 1. I want the sorting in such a way that it should show the result 3 as there are 3 elements in second row - E1,B1,C1 .