DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Create Data Frame From Variable Number Of Vectors

04.19.2007
| 3704 views |
  • submit to reddit
        // Create a data frame from a varied number of vectors
// Taken from http://article.gmane.org/gmane.comp.lang.r.general/56501/match=create+data+frame

N1 <-c(1,2,3,4)
N2 <-c(1,2,3,4)
N3 <-c(1,2,3,4)
abc <-c(1,2,3)
lab <- paste("N", seq(along=abc), sep="")
D <- data.frame(lapply(lab, get))
names(D) <- lab