Skip to content

Instantly share code, notes, and snippets.

@andilabs
Created August 30, 2013 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andilabs/6388734 to your computer and use it in GitHub Desktop.
Save andilabs/6388734 to your computer and use it in GitHub Desktop.
run R function on certain columns of data frame and then paste the result to the whole data frame
time_spent <- function(from,to) {
op <- options(digits.secs = 3)
x<-as.numeric((strptime(to, "%Y-%m-%d %H:%M:%OS")-strptime(from, "%Y-%m-%d %H:%M:%OS")),units="secs")
data.frame(time_spent=x)
}
dane_evaluations<-data.frame(dane_evaluations,time_spent=apply(dane_evaluations[,c('documentevaluation_start','documentevaluation_end')],1,function(x) time_spent(x[1], x[2])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment