Last active
August 29, 2015 14:02
-
-
Save mplourde/153f021018e361315916 to your computer and use it in GitHub Desktop.
building a data.frame column wise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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