Generating variable names for dataframes based on the loop number in a loop in R

前端 未结 2 1137
执念已碎
执念已碎 2021-01-29 02:32

I am working on developing and optimizing a linear model using the lm() function and subsequently the step() function for optimization. I have added a variable to my dataframe b

2条回答
  •  囚心锁ツ
    2021-01-29 03:02

    For your first question:

    You can create the strings as before, using

    df.names <- paste(("Run",1:10,sep="")
    

    Then, create your for loop and do the following to give the data frames the names you want:

    for (i in 1:10){
       d.frame <- # create your data frame here
       assign(df.name[i], d.frame)
    }
    

    Now you will end up with ten data frames with ten different names.

    For your second question about the coefficients:

    As far as I can tell, these don't naturally fit into your data frame structure. You should consider using lists, as they allow different classes - in other words, for each run, create a list containing a data frame and a numeric vector with your coefficients.

提交回复
热议问题