library(foreach) library(survival) my.coxph = function(x, t, e) # Simple CoxPH with silenced errors. { m = try(coxph(Surv(t,e)~x, data=data.frame(t=t,e=e,x=x)), silent=TRUE) p = NA if (!inherits(m, 'try-error')) { s = summary(m); p = s$coefficients['x', 5] } return (p) } # foreach with a cluster backend library(doParallel) cl = makeCluster(4, type='PSOCK') # or 'FORK' registerDoParallel(cl) itx = iter(X, by='column') pv = foreach(z=itx, .combine='c') %dopar% my.coxph(z, C$t.rfs, C$e.rfs) stopCluster(cl) # foreach with multicore backend library(doMC) registerDoMC(4) itx = iter(X, by='column') pv = foreach(z=itx, .combine='c') %dopar% my.coxph(z, C$t.rfs, C$e.rfs)