It's ideal to pose these kinds of questions with a reproducible example, FAQ: How to do a minimal reproducible example ( reprex ) for beginners
But without one I think we can still guess at what's going on. One way you can get this error is when your data frame CF_1604_VGD_OCC
hasn't been initialized yet or has only NULL values.
For example, you expect this to happen,
library(tidyverse)
df <- tibble(
x = c(1:3,NA)
)
df$x[is.na(df$x)]<-"N"
df
#> # A tibble: 4 × 1
#> x
#> <chr>
#> 1 1
#> 2 2
#> 3 3
#> 4 N
But instead, you have,
df$x <- NULL
df$x[is.na(df$x)]<-"N"
#> Warning: Unknown or uninitialised column: `x`.
#> Error:
#> ! Assigned data `<chr>` must be compatible with existing data.
#> ✖ Existing data has 4 rows.
#> ✖ Assigned data has 0 rows.
#> ℹ Only vectors of size 1 are recycled.
Created on 2022-12-06 by the reprex package (v2.0.1)