Reputation: 75
I have a sample vector with NA, I want to replace these NA with NULL
ts<-c(12,NA,45,16,48,69,NA,3)
I tried this but it didn't work
ts[is.na(ts)]<-NULL
is there anyway to do this? Thanks.
Upvotes: 3
Views: 10264
Reputation: 13319
Doesn't make it a real NULL
but does the job.
forcats::fct_explicit_na(as.character(ts),"NULL")
Upvotes: 0
Reputation: 2141
As far as i know a vector can't contain the value NULL. It will just get omitted. For example
ts <- c(1,2,NULL,NULL)
ts
[1] 1 2
Why do you want to do this replacement in the first place?
Upvotes: 1