My question is a very basic one and I am new to R and programming. I have a data frame RESULT
with two columns Max
, Min
and 500 rows. I just want to find the difference between Max
and Min
and put the value in a third column Difference
. I tried with the code:
select Max, Min, Max-Min as Difference from RESULT.
But I am getting
Error: unexpected symbol in "select Max".
I also tried just with:
Difference<-c(RESULT$Max-RESULT$Min)
for which I am getting:
Warning Message
In Ops.factor(RESULT$Max, RESULT$Min) :
- not meaningful for factors
RESULT:
Max Min
1 NaN NaN
2 25 NaN
3 NaN NaN
4 NaN NaN
5 NaN NaN
6 25.6 23.1
I want to display NaN
or any other variable like X
or Y
in Difference
column whenever there is NaN
in Either of Max
or Min
. The output should be like:
Max Min Difference
1 NaN NaN NaN
2 25 NaN NaN
3 NaN NaN NaN
4 NaN 34 NaN
5 NaN NaN NaN
6 25.6 23.1 2.5
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…