applying function on data.table having two columns as factors

I have a R data.table that looks like the 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, for different combinations of (User_ID,Exec_No) I need a vector of all Job_No that fall into the 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 would prefer the output of the operation to be a list of lists.

How do I achieve this in R in a quick manner considering that the input data.table will have around half a million rows?

Answers


Here you 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))),
     by = list(user.id, exec.no)][, result]

Need Your Help

How can you programatically create projects and build types in TeamCity?

java teamcity

I have been studying the TeamCity OpenAPI and I'm trying to figure out if it's possible to create new projects and build types programatically. As far as I understand, it's not exactly possible via...

app.config “forced” (?) on .net 4.0.. is it needed?

.net-4.0 upgrade app-config

It seems that when upgrading a project to .net 4.0 in VS 2010 Beta 2,

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.