[R] How to preserve NULL in vector

Duncan Murdoch murdoch at stats.uwo.ca
Mon Apr 6 15:34:16 CEST 2009


On 4/6/2009 9:24 AM, Daren Tan wrote:
> I have a vector containing NULL. Referencing to that NULL gives me NA
> instead, which disrupt my codes. How can i preserve NULL as it is ?

NULL is not a numeric value, so you can't put it in a numeric vector. 
When you tried, it got converted to the numeric value NA.

You can have a list containing NULL, and lists are vectors, but 
functions that expect *numeric* vectors generally won't work with them.

Duncan Murdoch

> 
>> res <- c(1,2,NULL)
>> res[1]
> [1] 1
>> res[2]
> [1] 2
>> res[3]
> [1] NA
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list