Data.table: fcase() could do vectorized switch on character first input

Created on 24 Nov 2020  路  3Comments  路  Source: Rdatatable/data.table

A cool feature of SQL CASE WHEN is

  CASE x
    WHEN 1 then '1'
    WHEN 2 then '2'
    ELSE '>2'
  END as switched_case

It would be nice to mimic this in fcase:

fcase(
  x,
  1, '1',
  2, '2',
  default = '>2'
)

Most helpful comment

maybe it should be a seprated function fswitch()

All 3 comments

maybe it should be a seprated function fswitch()

@shrektan , is that different from kit::nswitch you asked for ?

no but just data.table should have no dependencies and if we add in data.table we may should choose to implement it as a wrapper of fcase.

Was this page helpful?
0 / 5 - 0 ratings