Skip to content

how to create data.frame with dynamic count of values

3 messages · Knut Krueger, jim holtman, Don MacQueen

#
Hello R-Group

I found how to fill the data.frame ->
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/70843.html

N1 <- rnorm(4)
N2 <- rnorm(4)
N3 <- rnorm(4)
N4 <- rnorm(4)
X1 <- LETTERS[1:4]
###################
nams <- c(paste("N", 1:4, sep = ""), "X1")
dat <- data.frame(lapply(nams, get))
names(dat) <- nams
dat


But I need also to create a dynamic count of numeric vectors
items = 15
VarSize <-10

N1 <- rep(0,VarSize)
N2 <- rep(0,VarSize)
N3 <- rep(0,VarSize)
N4 <- rep(0,VarSize)
N5 <- rep(0,VarSize)
...
N15<- rep(0,VarSize)  # 15 items


Thank you in advance
Knut
2 days later
#
Perhaps you didn't want a dataframe with columns N1 to N15 in it.

Perhaps the assign() function is what you are looking for. Something 
similar to:

nams <- paste('N',1:15,sep='')
for (nm in nams) assign(nm,rep(0,VarSize))

-Don
At 10:14 PM +0100 12/8/06, Knut Krueger wrote: