Data Type Error Occurs When Calculating Based on Conditions for Each Group

For example, suppose you have executed “Group By” before performing “Calculate Based on Condition.”

When you execute “Calculate Based on Condition” in this grouped state, the following error may occur:

Error in mutate(., across(c(Value, Value1), .names = "{col}_lag_pct",  : 
  ℹ In argument: `across(...)`.
Caused by error:
! `Value_lag_pct` must return compatible vectors across groups.
ℹ Result of type <double> for group A: `ID = "A"`.
ℹ Result of type <character> for group B: `ID = "B"`.

This error occurs when grouping and automatic data type detection are used together, causing some groups to have numeric data types while others have character data types.

Therefore, you can avoid this error by explicitly specifying the data type as “Character” before execution.