[R] Extracting data using subset function

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Sun Feb 5 23:18:05 CET 2023

On Sun, 5 Feb 2023 15:13:54 -0500
Duncan Murdoch <murdoch.duncan using gmail.com> wrote:

> Just to build the mountain a little higher, I would use
>    subset(p, seq_along(p) <= 20)
> You should generally avoid expressions like "1:length(p)", because
> they don't do what you would expect in the unusual case that p is
> length 0.
> Even in cases where you know p is not length 0, it's a good habit to
> get into so that in the future you don't get surprised.

Aaarrrggghhh.  That was a dumb-dumb on my part.  As Burns said to
Ripley (fortunes::fortune(26)), good catch.




Honorary Research Fellow
Department of Statistics
University of Auckland
Stats. Dep't. phone: +64-9-373-7599 ext. 89622
Home phone: +64-9-480-4619

More information about the R-help mailing list