Assigned data `value` must be compatible with existing data.

> CF_1604_VGD_OCC$'1'[is.na(CF_1604_VGD_OCC$'1')]<-"N" 
Error:
! Assigned data `value` must be compatible with existing data.
✖ Existing data has 3 rows.
✖ Assigned data has 0 rows.
ℹ Only vectors of size 1 are recycled.
Run `rlang::last_error()` to see where the error occurred.
Warning messages:
1: Unknown or uninitialised column: `1`. 
2: Unknown or uninitialised column: `1`.

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)

your first problem is your attempting to use $ syntax to access column which does not conform to standard naming conventions. If you have to do this; then the way is with back-tick symbol, not any other type of quote

# Not: 
CF_1604_VGD_OCC$'1'
# Rather
CF_1604_VGD_OCC$`1`
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.