Skip to content

Should numeric()/character() etc initialize with NA instead of 0 or ""?

2 messages · Fabian Scheipl, Brian Ripley

#
On Mon, 5 Nov 2007, Fabian Scheipl wrote:

            
Lots of code relies on this.  It's common programming practice (and not 
just in R/S).
But using x <- rep(NA_real_, n) does this for you, and is much clearer to 
the reader. Using x <- numeric(n) is only appropriate if you want '0.0' 
elements.
You were specifically asked not to do that.