Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing loop output in a dataframe in R

Tags:

loops

for-loop

r

I want to know how to store the values of the complete loop output into a single dataframe in R. For example,

for(i in unique(x$id)){
    .
    .
    .
    y=output of one iteration}

At the end of each iteration, I am getting the output in y. But I want to store output of all iterations into y. How do I do that in R?

like image 417
ijaz ahamed Avatar asked Nov 30 '22 17:11

ijaz ahamed


1 Answers

You can do this simply by

y  <- NULL;
for (i in unique(x$id))
 { 
  tmp <- [output of one iteration]
  y <- rbind(y, tmp)
 }
like image 137
penguin2718 Avatar answered Dec 22 '22 10:12

penguin2718