title: Cleaning `Inf` values from an R dataframe
body: <p>In R, I have an operation which creates some <code>Inf</code> values when I transform a dataframe.  </p>
  
  <p>I would like to turn these <code>Inf</code> values into <code>NA</code> values.  The code I have is slow for large data, is there a faster way of doing this? </p>
  
  <p>Say I have the following dataframe: </p>
  
  <pre><code>dat &lt;- data.frame(a=c(1, Inf), b=c(Inf, 3), d=c("a","b"))
  </code></pre>
  
  <p>The following works in a single case: </p>
  
  <pre><code> dat[,1][is.infinite(dat[,1])] = NA
  </code></pre>
  
  <p>So I generalized it with following loop</p>
  
  <pre><code>cf_DFinf2NA &lt;- function(x)
  {
      for (i in 1:ncol(x)){
            x[,i][is.infinite(x[,i])] = NA
      }
      return(x)
  }
  </code></pre>
  
  <p>But I don't think that this is really using the power of R. </p>