wwl
wwl

Reputation: 2065

R using max function in data table

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?

Upvotes: 1

Views: 3183

Answers (1)

wwl
wwl

Reputation: 2065

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

AfAm[, sizediffpos := pmax(0,sizediff)]

Upvotes: 4

Related Questions