My data sample_final1 has a column called datadate, it is in Date format and has a lot of NAs. When I use the code as below
sample_final1[
, ':=' (earnann = ifelse(is.na(datadate) == TRUE, 1L, 0)) , by = secid
]
I got the error message:
Error in `[.data.table`(sample_final1, , `:=`(earnann = ifelse(is.na(datadate) == :
Type of RHS ('integer') must match LHS ('double'). To check and coerce would impact performance too much for the fastest cases. Either change the type of the target column, or coerce the RHS of := yourself (e.g. by using 1L instead of 1)
However, if I delete the grouping option, it works well. I do not understand how this should be fixed.