title: same loop for all column in R to create new data frame
body: <p>For the following data frame,</p>
  
  <pre><code>mydata=data.frame(x1=c(4,8,7,12,10),x2=c(5,7,18,4,12),x3=c(10,12,5,2,14))
  mydata
    x1 x2 x3
  1  4  5 10
  2  8  7 12
  3  7 18  5
  4 12  4  2
  5 10 12 14
  </code></pre>
  
  <p>I would like to create a new 3 columns where each column will be created by repeating each element 12 times. For the first new column,  </p>
  
  <pre><code>y1=matrix(NA, nrow=5,ncol=12)
  for ( g in 1:5){
    y1[g,]=rep(mydata$x1[g],12)
  }
  ynew_1=c(apply( y1, 1, c))
  </code></pre>
  
  <p>ynew_1</p>
  
  <pre><code> 4  4  4  4  4  4  4  4  4  4  4  4  8  8  8  8  8  8  8  8  8  8  8  8  7  7  
  7  7  7  7  7  7  7  7  7  7 12 12 12 12 12 12 12 12 12 12 12 12 10 10 10 10 10 10 10 10 10 10 10 10
  </code></pre>
  
  <p>I can create ynew_2 and ynew_3 in a similar way. <strong>Can I use any function or loop to create these new variables</strong>? Any help would be appreciated</p>