title: Replace mean of the column using for loop in R
body: <p>I have a data-set which contain fifty question (Q1 to Q50) . The value of this question is likert scale data from 1 to 5 . But in my data set i have some missing value so i want to replace missing value by its column mean value . Here is a sample code for single column </p>
  
  <pre><code>demodata$Q1 = ifelse(is.na(demodata$Q1),
                   ave(demodata$Q1, FUN = function(x)mean(x, na.rm = TRUE)),
                   demodata$Q1)
  </code></pre>
  
  <p>Now the problem is i have around 50 question in my data set . So its very tough to perform same operation each and every time . How can i manage this using a for loop or any easy technique ? </p>