I seem to have stumbled upon a predicament in my efforts to learn using R. I have a dataset that looks like this:
col1 / col2 / col3 NA / 1 / 2 1 / NA /2
What I need to do is replace everything that IS NOT NA with another value (see below)
Col1 / col2 / col 3 NA / Data / Data Data / NA/ Data
I’ve looked everywhere on the web, it seems that everybody wants to replace NA‘s with other values, I on the other hand need the exact opposite but was unable to find any command. I even looked into “IF’s” but was only able to find functions that replace values if they are eiter < or = or > to a certain number. I need something that will specify…”IF different from NA, then replace with….”
The data:
To choose all values that are not
NA, use the logical operator!(“not”) together withis.na:The same can also be achieved with the
replacefunction:Another approach is needed if you want to replace the values of factors. This can be achieved with the following command: