Append data frames together in a for loop

后端 未结 8 1718
無奈伤痛
無奈伤痛 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条回答
  •  天命终不由人
    2020-11-28 20:07

    x <- c(1:10) 
    
    # empty data frame with variables ----
    
    df <- data.frame(x1=character(),
                         y1=character())
    
    for (i in x) {
      a1 <- c(x1 == paste0("The number is ",x[i]),y1 == paste0("This is another number ", x[i]))
      df <- rbind(df,a1)
    }
    
    names(df) <- c("st_column","nd_column")
    View(df)
    

    that might be a good way to do so....

提交回复
热议问题