Re: [R] Adding columns to a 2D vector

2015-06-03 Thread Sarah Goslee
Hi, On Wed, Jun 3, 2015 at 8:26 AM, Thomas Chesney wrote: > I'd like to add some columns into the middle of this: > > vec <- c(1, -1) > lst <- lapply(numeric(n-1), function(x) vec) > combos <- as.matrix(expand.grid(lst)) > colnames(combos) <- NULL This isn't quite reproducible, since n is undefi

[R] Adding columns to a 2D vector

2015-06-03 Thread Thomas Chesney
I'd like to add some columns into the middle of this: vec <- c(1, -1) lst <- lapply(numeric(n-1), function(x) vec) combos <- as.matrix(expand.grid(lst)) colnames(combos) <- NULL The way I have used is: combos2 <- matrix(NA, nrow=64, ncol=9) combos2[,1] <- 0 combos2[,2] <- combos[,1] combos2[,3]