> I am looking at the Braun/Murdoch book, " A First Course in
> Statistical Programming in R", and I have a question about a function
> there.  It's on page 52, Example 4.5; the sieve of Erastosthenes.
> 
> There is a line:
> primes <- c()
> 
> Is there a difference between using that and
> primes <- NULL
> please?
> 
> When you put in primes <- c(), primes comes back as NULL.

They return the same thing
identical(c(), NULL)    #TRUE

> Is one more efficient or is this just a matter of programming style, 
please?
system.time(for(i in 1:1000000) c())
#   user  system elapsed 
#   0.63    0.02    0.64 

system.time(for(i in 1:1000000) NULL)
#   user  system elapsed 
#   0.28    0.00    0.28

Using NULL appears to be quicker on my machine, but given that you can do 
a million of these assignments in a fraction of a second, it makes no 
practical difference.  NULL is perhaps more intuitive than c() for 
demonstrating that the variable is empty.

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

______________________________________________
R-help@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.

Reply via email to