title: how to store output to list in for loop in r
body: <p>I am doing web scraping of a website. When I fetch the data from a website every page has 10 observations. I am writing a function where you can specify no of pages to scrape and finally store it in a list and later convert it into dataframe.</p>
  
  <pre><code>library(jsonlite)
  forum_data_fetch &lt;- function(no_of_pages) {
  
     pages &lt;- seq(no_of_pages)
     #print(pages)
     forum_data &lt;- list()
  
     for(i in 1:length(pages)){
         tmp &lt;- fromJSON(paste("http://mmb.moneycontrol.com/index.php?q=topic/ajax_call&amp;section=get_messages&amp;offset=&amp;lmid=&amp;isp=0&amp;gmt=cat_lm&amp;catid=1&amp;pgno=",i,sep=""))
         forum_data[[i]] &lt;- tmp
  
    }
  
     dat &lt;- as.data.frame(forum_data)
     dat &lt;- dat[,c("msg_id","border_msg_count","user_id","border_level_text","follower_count", "topic", "tp_sector","tp_msg_count","heading", "flag", "price", "message")]
  
   return(dat)
  
  }
  
   test &lt;- forum_data_fetch(3)
  </code></pre>
  
  <p>Ideally, the above function returns 30 observations, but it returns only 10. I think I am doing something wrong while storing the list as a data.frame</p>