title: Access to column name of dataframe with *apply function
body: <p>I need to make tutorial for beginner using the R *apply function (without using reshape or plyr package in a first time)</p>
  
  <p>I try to <code>lapply</code> (because i read <code>apply</code> is not good for dataframe) a simple function to this dataframe, and i want to use named column to access data : </p>
  
  <pre><code>fDist &lt;- function(x1,x2,y1,y2) {
    return (0.1*((x1 - x2)^2 + (y1-y2)^2)^0.5)  
  }
  
  data &lt;- read.table(textConnection("X1 Y1 X2 Y2
   1 3.5 2.1 4.1 2.9
   2 3.1 1.2 0.8 4.3
   "))
  
  data$dist &lt;- lapply(data,function(df) {fDist(df$X1 , df$X2 , df$Y1 , df$Y2)})
  </code></pre>
  
  <p>I have this error <code>$ operator is invalid for atomic vectors</code>, it is probably because the dataframe is modified by laply ?... is there a best way to do that with $ named column? </p>
  
  <p>I resolve my first question with @DWin answer. But i have another problem, misunderstanding, with mixed dataframe (numeric + character) : </p>
  
  <p>In my new use case, i use two function to compute distance, because my objective is to compare a distance Point between all of other Point.</p>
  
  <pre><code>data2 &lt;- read.table(textConnection("X1 Y1 X2 Y2
       1 3.5 2.1 4.1 2.9
       2 3.1 1.2 0.8 4.3
       "))
  
  data2$char &lt;- c("a","b")
  
  fDist &lt;- function(x1,y1,x2,y2) {
   return (0.1*((x1 - x2)^2 + (y1-y2)^2)^0.5) 
  }
  
  fDist2 &lt;- function(fixedX,fixedY,vec) { 
   fDist(fixedX,fixedY,vec[['X2']],vec[['Y2']])
  }
  
  # works with data (dataframe without character), but not with data2 (dataframe with character)
  #ok
  data$f_dist &lt;- apply(data, 1, function(df) {fDist2(data[1,]$X1,data[1,]$Y1,df)})
  #not ok
  data2$f_dist &lt;- apply(data2, 1, function(df) {fDist2(data2[1,]$X1,data2[1,]$Y1,df)})
  </code></pre>