Skip to content
Back to formatted view

Raw Message

Message-ID: <4B055E31.9000109@googlemail.com>
Date: 2009-11-19T15:03:13Z
From: Stephan Dlugosz
Subject: Efficient cbind of elements from two lists

Hi!

I have a data.frame "data" and splitted it.

data <- split(data, data[,1])

This is a quite slow procedure; and I do not want to do it again. So, 
any unsplit and "resplit" is no option for me.
But: I have to cbind "variables" to the splitted data from another list, 
that contains of vectors with matching sizes, so

for (i in 1:length(data)) {
   data[[i]] <- cbind(data[[i]], l[[i]]))
}

works well; but very, very slowly.
The lapply solution:

data <- lapply(1:k, function(i) cbind(data[[i]], l[[i]]))

does not improve the situation, but allows for mclapply from the 
multicore package...
Is there a more efficient way to combine elements from two lists?

Thank you very much!

Greetings,
Stephan