[R] question from Braun/Murdoch book
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Oct 8 09:11:12 CEST 2008
On Wed, 8 Oct 2008, Erin Hodgess wrote:
> Hi R People:
>
> 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.
>
>
> Is one more efficient or is this just a matter of programming style, please?
What would be more efficient is primes <- integer(0) (as it looks like
'primes' concatenates integer vectors, at a quick glance).
Use a function call c() to get NULL is not efficient, but all the
differences here are tiny.
> Thanks in advance,
> Sincerely,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodgess at gmail.com
>
> ______________________________________________
> 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.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list