[R] lapply to multivariate function?

2013-09-01 Thread Ignacio Martinez
I have a Data Frame that contains, between other things, the following fields: userX, Time1, Time2, Time3. The number of observations is 2000. I have a function that has as inputs userX, Time1, Time2, Time3 and return a data frame with 1 observation and 19 variables. I want to apply that

Re: [R] lapply to multivariate function?

2013-09-01 Thread Rui Barradas
Hello, Maybe you need apply, not lapply. It seems you want to apply() a function to the first dimension of your data.frame, something like apply(dat, 1, fun) #apply by rows Hope this helps, Rui Barradas Em 01-09-2013 15:00, Ignacio Martinez escreveu: I have a Data Frame that contains,

Re: [R] lapply to multivariate function?

2013-09-01 Thread Bert Gunter
Rui et.al.: But apply will not work if the data frame has columns of different classes/types, as appears to be the case here. Viz, from ?apply: If X is not an array but an object of a class with a non-null dimhttp://127.0.0.1:12824/help/library/base/help/dim value (such as a data frame),apply

Re: [R] lapply to multivariate function?

2013-09-01 Thread Bert Gunter
Oh, another possibility is ?mapply, which I should have pointed out in my previous reply. Sorry. -- Bert On Sun, Sep 1, 2013 at 8:30 AM, Bert Gunter bgun...@gene.com wrote: Rui et.al.: But apply will not work if the data frame has columns of different classes/types, as appears to be the

Re: [R] lapply to multivariate function?

2013-09-01 Thread Ignacio Martinez
I hope this reproduceble example helps understand what I'm trying to do. This is the function: # Make Data Frame for video actions between given times for user X DataVideoActionT - function (userX, Time1, Time2, Time3){ #Get data for user X videoActionsX-subset(videoLectureActions,

Re: [R] lapply to multivariate function?

2013-09-01 Thread Rui Barradas
Hello, Your example doesn't really run, but for what I've seen, if your second data frame is named dat2, something along the lines of n - nrow(dat2) res - list(vector, n) for(i in 1:n){ res[[i]] - with(dat2, DataVideoActionT(anon_ID[i], Time1[i], TimeM[i], TimeL[i])) } do.call(rbind, res)

Re: [R] lapply to multivariate function?

2013-09-01 Thread Ignacio Martinez
Thanks a lot Rui. Loops make sense to me. I made one modification to your code. I have thousands of observation, so I would like to run it in parallel. This is my reproducible example: # Make Data Frame for video actions between given times for user X DataVideoActionT - function (userX, Time1,

Re: [R] lapply to multivariate function?

2013-09-01 Thread Rui Barradas
Hello, I have no experience with packages foreach and doMC. But I believe that paralel computing only pays if the datasets are really large, due to the setup time. Maybe thousands of observations is not that large. Rui Barradas Em 01-09-2013 22:21, Ignacio Martinez escreveu: Thanks a lot