title: R- Normalizing certain columns from 0 to 1 with values equal to 0
body: <p>I recently started with are and I would like to scale my data matrix. I found a way to do that here <a href="https://stackoverflow.com/questions/5468280/scale-a-series-between-two-points">Scale a series between two points
  </a></p>
  
  <pre><code>x &lt;- data.frame(step = c(1,2,3,4,5,6,7,8,9,10))
  normalized &lt;- (x-min(x))/(max(x)-min(x))
  </code></pre>
  
  <p>As my data consists of several columns whereof I only want to normalize certain columns using a function was suggested.</p>
  
  <pre><code>normalized &lt;- function(x) (x- min(x))/(max(x) - min(x))
  x[] &lt;- lapply(x, normalized) 
  </code></pre>
  
  <p>Additionally, I realized that some of the data points in my dataset equal 0 such that the presented formula doesn't work anymore. I added an extension suggested here: <a href="https://stackoverflow.com/questions/31926022/scaling-r-dataframe-to-0-1-with-na-values">scaling r dataframe to 0-1 with NA values</a></p>
  
  <pre><code>normalized &lt;- function(x, ...) {(x - min(x, ...)) / (max(x, ...) - min(x, ...))}
  </code></pre>
  
  <p>But I don't understand how I have to code it. For example, I would like to have column 4,5,6 and 10 normalized but I would like to have the remaining columns as they were in the data set?
  I tried it for column 4:</p>
  
  <pre><code>data &lt;- lapply(data[,4],normalized,na.rm= TRUE)
  </code></pre>
  
  <p>But it did not work (instead of a data frame a list resulted :-(...), does anybody knows how I could fix it?</p>
  
  <p>Thanks a lot already in advance!</p>