How can I calculate the difference between the largest and smallest value row-wise, for each column when there are plenty of NA?
Let’s assume this is my data:
a b c d e
A 1 NA 3 NA NA
B 0 NA 6 NA 2
C 3 2 1 NA 3
C NA NA 3 NA 0
For each column, I want to find the difference between the row with the highest value and the row with the lowest value – the result should look like this:
3 0 5 NA 3
I have hundreds of columns to analyse so I need a code that is easy to handle (eg: I won’t need to manually input the column names).
Any help will be greatly appreciated!
M. Miguel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.