Skip to content

Instantly share code, notes, and snippets.

@mplourde
Last active August 29, 2015 14:02
Show Gist options
  • Save mplourde/153f021018e361315916 to your computer and use it in GitHub Desktop.
Save mplourde/153f021018e361315916 to your computer and use it in GitHub Desktop.
building a data.frame column wise
num.cols <- 10
# allocate space for your ten columns
cols <- vector('list', num.cols)
# add key column, such as timestamp
cols[[1]] <- 1:5
for (i in 2:num.cols) {
cols[[i]] <- rnorm(5) # add the next column, 5 random numbers
}
# add the column names
names(cols) <- c('timestep', letters[1:9])
# convert the list to a data.frame
d <- data.frame(cols)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment