I have a list of standard errors and standard deviations by date, like so:
date avg_stdev avg_sterr
2016-11-25 0.02345404 0.009561593
2016-11-27 0.02098070 0.009600404
2016-11-28 0.02098070 0.009600404
2016-11-29 0.02098070 0.009600404
2016-11-30 0.02009983 0.008637851
2016-12-03 0.01793612 0.008303243
I want to create two new columns that are the higher and the lower of those. (So in each of these particular rows, avg_stlow
would equal avg_sterr
and avg_sthigh
would be avg_stdev
, but the values will cross later on.)
I tried doing dt[,avg_stlow := min(avg_stdev, avg_sterr)]
, but this just gives me the minimum value from the columns. I also tried dt[,avg_stlow := if(avg_stdev > avg_sterr) avg_sterr else avg_stdev]
, but this seems to determine which column is less (by some means) and use that column throughout. How can I get it to evaluate based on the value for each row?