[R] How to split DF into a list and avoid NULL elements in this list

Lauri Nikkinen lauri.nikkinen at iki.fi
Tue Nov 25 16:00:11 CET 2008


Hello,

I'm trying to split my DF into a list using incremental loop. How can
I avoid NULL elements in this list?

DF <- data.frame(var1 = 1:10, var2 = 11:20, var3 = 21:30, var4 = 31:40)

x <- list()
i <- 1
while (i <= ncol(DF)-1) {
          x[[i]] <- DF[, i:c(i+1)]
          i <- i + 2
}
x

Many thanks,
Lauri



More information about the R-help mailing list