Create calculation fails with no applicable method for 'count' applied to an object of class "c('double', 'numeric')"

Problem

When using the count() function within a Create Calculation step, you may encounter the following error:

Error in count(...) : no applicable method for 'count' applied to an object of class "c('double', 'numeric')"

This occurs because count() is designed to work on data frames or grouped data, not on individual columns or vectors within a calculation context.

Solution

Use n() instead of count() in your Create Calculation step.

Why this works: The n() function is specifically designed for use within data manipulation operations (like summarize() or mutate()) and returns the number of observations in the current group or dataset, making it the appropriate choice for calculations.

Example:

# Instead of this (which causes an error):
count(column_name)

# Use this:
n()

If you need to count specific conditions, you can combine sum() with logical conditions:

# Count rows where a condition is TRUE
sum(column_name > 10, na.rm = TRUE)