[R] Minor documentation issue
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Apr 22 09:27:32 CEST 2006
On Fri, 21 Apr 2006, Duncan Murdoch wrote:
> On 4/21/2006 9:26 PM, Vivek Satsangi wrote:
>> (Sorry about the last email which was incomplete. I hit 'send' accidentally).
>>
>> I looked at ?seq. One of the forms given under "Usage" is seq(from).
>> This would be the form used if seq is called with only one argument.
>> However, this should actually say seq(to). For example,
>>> seq(1)
>> [1] 1
>>> seq(3)
>> [1] 1 2 3
>
> Try this:
>
> > debug(seq.default)
> > seq(3)
>
> You'll then drop into the browser at the start of executing the
> seq.default function. You can print the value of "to" and of "from",
> and you'll see this:
>
> Browse[1]> to
> [1] 1
> Browse[1]> from
> [1] 3
>
> So the documentation is correct, even if the usage in this case is the
> reverse of English usage.
And the documentation says
The last generates the sequence '1, 2, ..., length(from)' (as if
argument 'along' had been specified), _unless_ the argument is
numeric of length 1 when it is interpreted as '1:from' (even for
'seq(0)' for compatibility with S).
Also try naming arguments
> seq(to=3)
[1] 1 2 3
> seq(from=3)
[1] 1 2 3
> seq(from=1:3)
[1] 1 2 3
> seq(from=2:4)
[1] 1 2 3
> seq(to=2:4)
[1] 1 2
(with a warning) so it really is different from seq(to=).
Because of the caveat, I suggest you always use seq(len=) for this case.
--
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