how to cbind the column generated in a loop in R -
i have loop gives me column of data per run. run loop in range 0:4, gives me 5 columns. if print out, column1, column2, ... want save of 5 columns csv file. in 1 single file, want have 5 columns ordered order of loop, namely, column1, column2, ...
there many ways achieve have described. here 1 approach work in many circumstances.
# start empty list mydata <- list() # run through loop, adding each vector list for(i in 1:10){ # whatever in loop mydata[[i]] <- # result of iteration of loop } # turn list dataframe mydf <- data.frame(mydata) # write dataframe file write.csv(mydf, file="destfile.csv")
Comments
Post a Comment