r - applying function on data.table having two columns as factors -


i have r data.table looks below table

    user_id exec_no job_no 1:    2      1      1    2:    2      2      2  3:    3      2      3 4:    1      2      4 5:    1      1      5 6:    3      2      6 7:    2      2      7 8:    1      1      8 

now, different combinations of (user_id,exec_no) need vector of job_no fall category.

 list (    list(user_id = 2, exec_no = 1, job_nos = c(1)) ,    list(user_id = 2, exec_no = 2, job_nos = c(2,7)) ,    list(user_id =3, exec_no = 2, job_nos = c(3,6)) ,    list(user_id =1, exec_no = 2, job_nos = c(4)) ,    list(user_id =1, exec_no = 1, job_nos = c(5,8))   )  

i prefer output of operation list of lists.

how achieve in r in quick manner considering input data.table have around half million rows?

here go:

dt = data.table(user.id = c(2,2,3,1,1,3,2,1), exec.no = c(1,2,2,2,1,2,2,1), job.no = c(1:8))  dt[, list(result = list(list(user.id = user.id,                              exec.no = exec.no,                              job.nos = job.no))),      = list(user.id, exec.no)][, result] 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -