1

I'm using R and have a problem in a data.table

Both of these commands return NA for all rows:

AfAm[, sizediffpos := max(0,sizediff)]
AfAm[, sizediffpos := max(0,sizediff, na.rm = TRUE)]

Is there any way I can rectify the error?

wwl
  • 2,025
  • 2
  • 30
  • 51
  • 1
    `?pmax` instead? http://stackoverflow.com/questions/19994543/how-can-i-take-pairwise-maximum-between-two-vectors-in-r – rawr Oct 20 '16 at 20:43

1 Answers1

4

As rawr points out, the correct way is to use pmax:

AfAm[, sizediffpos := pmax(0,sizediff)]
wwl
  • 2,025
  • 2
  • 30
  • 51