d*******1 发帖数: 854 | 1 比如
FOR (I=1: 20), 每一个循环都要产生一个DATAFRAME 如 TEST1, TEST2, TEST3......,
也就是说把循环数作为DATAFRAME名字的后缀, 怎么弄呢? 谢了 | l*********s 发帖数: 5409 | 2 1. name these dataframes within a list "environment"
2. use assign function | d*******1 发帖数: 854 | 3 can you be more specific on the first step? thanks
【在 l*********s 的大作中提到】 : 1. name these dataframes within a list "environment" : 2. use assign function
| l*********s 发帖数: 5409 | 4 for instance,
totn <- 100
tmpdflst <- NULL
dfnames <- paste("tmp", 1:totn, sep="_")
for(i in 1:totn){
tmpdflst[[ dfnames[i] ]] <- ... ( whatever generates your series of df )
}
attach(tmdflst) if you want to save some keystrokes ( bad practice though)
【在 d*******1 的大作中提到】 : can you be more specific on the first step? thanks
| a********s 发帖数: 188 | 5 I recommend this way, using "assign" function:
iter <- 10
dtname <- paste("test", 1:iter, sep="")
for(i in 1:iter){
temp <- data.frame(x = 1:10, y = rnorm(10))
assign(dtname[i], temp)
} | d*******1 发帖数: 854 | 6 that is a great solution, thank you man!
【在 a********s 的大作中提到】 : I recommend this way, using "assign" function: : iter <- 10 : dtname <- paste("test", 1:iter, sep="") : for(i in 1:iter){ : temp <- data.frame(x = 1:10, y = rnorm(10)) : assign(dtname[i], temp) : }
|
|