title: R : Write CSV that has varying row values
body: <p>I am trying to write to a csv file from R, that has varying number of row values, </p>
  
  <pre><code>*for example*,
  1,2,3,4,5
  2,3,6
  2,3
  4,3,4,5
  </code></pre>
  
  <p>I have tried 3 possible attempts, but failed one way or the other.</p>
  
  <ol>
  <li><p>I created a data frame that has 1 column, and I wrote each values separated as comma. However, it fails to be treated like a regular csv when I open it in editor, and there are issues when I am importing it in R through <code>read.table</code></p>
  
  <p>forloop{</p>
  
  <p>row &lt;- paste0("",row,",",value)</p>
  
  <p>}</p>
  
  <p>dataframe[i,] &lt;- substring(row.temp,2)</p></li>
  </ol>
  
  <p>2.I created a data frame that has missing values NA for values that are not present like,</p>
  
  <pre><code>t  NA w e NA
  NA NA t q NA
  </code></pre>
  
  <p>And then I write to csv as </p>
  
  <pre><code>write.table(dataframe,file = "test.csv", row.names = FALSE , col.names = FALSE, na = "", quote = FALSE, sep = ",")
  </code></pre>
  
  <p>But, I have unnecessary <code>,</code> for NA values</p>
  
  <ol start="3">
  <li><p>Pushing each row to a vector and writing to csv each row by row.</p>
  
  <p>forloop{</p>
  
  <p>row.temp &lt;- c(row.temp,values)</p>
  
  <p>}
  write.table(temp,file = "test.csv", row.names = FALSE , col.names = FALSE, append=TRUE, sep = ",")</p></li>
  </ol>
  
  <p>But, the problem is each vector value is written to each new line.</p>
  
  <p>I want to create this CSV file with the format through R. What approach could I take to solve this. I'm sure many people must have faced this issue. Thanks!!</p>