Append data frames together in a for loop

后端 未结 8 1714
無奈伤痛
無奈伤痛 2020-11-28 19:21

I have a for loop which produces a data frame after each iteration. I want to append all data frames together but finding it difficult. Following is what I am

8条回答
  •  旧时难觅i
    2020-11-28 20:09

    Again maRtin is correct but for this to work you have start with a dataframe that already has at least one column

    model <- #some processing
    df <- data.frame(col1=model)
    
    for (i in 2:17)
    {
         model <- # some processing
         nextcol <-  data.frame(model)
         colnames(nextcol) <- c(paste("col", i, sep="")) # rename the comlum
         df <- cbind(df, nextcol)
    }
    

提交回复
热议问题