title: padding sequence in R
body: <p>I would like to create left padding column depending on the max number of element of a column in an efficient way.</p>
  
  <p>Let me detail the input and output
  My input data is this:</p>
  
  <pre><code>input &lt;- data.frame(path=c("2","4,3,4","3,1"))
  input
     path
  1     2
  2 4,3,4
  3   3,1
  </code></pre>
  
  <p>expected output:</p>
  
  <pre><code>  V1 V2 V3
  1  0  0  2
  2  4  3  4
  3  0  3  1
  </code></pre>
  
  <p>The logic base on the input is:</p>
  
  <p>1 - We look at the row having the maximum element ( on this example it is 3 because we have 4,3,4 in row number 2) we now know that we will need to create 3 column as output</p>
  
  <p>2 - for the row that doesn't have 3 element we backfill with 0.
  Since the first row has only 1 element i need to put two column with 0
  for the second row i can directly fill all columns because we have three elements,for the last row i have 2 elements so i need to backfill one 0.  </p>
  
  <p>My attempt which does the work but is dirty</p>
  
  <pre><code>input$path &lt;- as.character(input$path)
  lst &lt;- strsplit(input$path, ",")
  column_to_create &lt;- max(lengths(lst))
  output &lt;- list()
  i &lt;- 1
  for(i in 1:length(lst)){
    if (length(lst[[i]]) &lt; column_to_create) {
  
      nb_create &lt;- column_to_create - length(lst[[i]])
      output[[i]] &lt;- c(rep(0,nb_create),lst[[i]])
    }
    else{
      output[[i]] &lt;- lst[[i]]
    }
  
  }
  output &lt;- lapply(output,as.numeric)
  do.call(rbind,output)
  
       [,1] [,2] [,3]
  [1,]    0    0    2
  [2,]    4    3    4
  [3,]    0    3    1
  </code></pre>