title: Loop through each column and row, do stuff
body: <p>I think this is the best way to describe what I want to do:</p>
  
  <pre><code>df$column &lt;- ifelse(is.na(df$column) == TRUE, 0, 1)
  </code></pre>
  
  <p>But where column is dynamic. This is because I have about 45 columns all with the same kind of content, and all I want to do is check each cell, replace it with a 1 if there's something in it, a 0 if not. I have of course tried many different things, but since there seems to be no df[index][column] in R, I'm lost. I'd have expected something like this to work, but nope:</p>
  
  <pre><code>for (index in df) {
    for (column in names(df)) {
      df[[index]][[column]] &lt;- ifelse(is.na(df[[index]][[column]]) == TRUE, 0, 1)
    }
  }
  </code></pre>
  
  <p>I could do this quickly in other languages (or even Excel), but I'm just learning R and want to understand why something so simple seems to be so complicated in a language that's meant to work with data. Thanks! </p>