Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace NA with NULL

Tags:

null

r

na

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.

like image 645
Dasaru Avatar asked Dec 01 '25 13:12

Dasaru


1 Answers

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?

like image 163
Julian_Hn Avatar answered Dec 04 '25 04:12

Julian_Hn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!