-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Milestone
Description
Not sure the status of ifelse() speed in R these days. Years ago it used to be really slow and I avoided it. Is that still the case?
I've seen this idiom quite a bit in the wild :
DT[, newCol := ifelse(existingCol == 42, 1L, 2L)]under verbose=TRUE there's a message about the plonk. It's slow and RAM inefficient I assume (haven't tested).
Better would be using i, as per #2676 :
DT[existingCol==42, newCol:=1L, fill=2L]Nested ifelse(ifelse(ifelse())) also quite common. Either detect and warn about ifelse() usage and point to a document about how to avoid, or optimize it automatically. And if ifelse() in base is still slow, see why and try to improve it there.
raneameya