Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. v1<-c(1,1,1,1,1,2,2,2,3,3,3,3,3,3,3)
  2. v2<-c("Jan","Jan","Jan","Feb","Feb","Jan","Jan","Feb","Jan","Jan","Feb","Feb","Feb","Feb","Feb")
  3. v3<-c("A1","E1","F1","B1","A1","E1","B1","C1","B1","D1","E1","A1","B1","C1","F1")
  4. dt <- data.table(emp_id=v1,month=v2,work=v3)
  5.  
  6. temp1 <- dt[,.(list(work)),.(emp_id,month)]
  7. head(temp1)
  8.  
  9. temp2 <- temp1[,.(list(V1)),.(emp_id)]
  10. head(temp2)
  11.  
  12. temp2[,V1 := lapply(V1, unlist, use.names = F)]
  13. dt <- setnames(temp2,"V1","Events")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement