[Rd] (PR#9811) sequence(c(2, 0, 3)) produces surprising results,
bill at insightful.com
bill at insightful.com
Fri Jul 27 21:54:24 CEST 2007
On Fri, 27 Jul 2007, Prof Brian Ripley wrote:
> This is as doumented, and I think you could say the same thing of seq().
> BTW, sequence() allows negative inputs, and I don't think you want
> sum(input) in that case.
help(sequence) says contradictory things about
the nvec[i]==0 case:
For each element of 'nvec' the
sequence 'seq(nvec[i])' is created. ...
and
nvec: an integer vector each element
of which specifies the upper bound ...
0 is not the upper bound of seq(0).
In any case, a suitably general multisequence function
would probably want vectors of both to's and from's.
merge.data.frame() requires a combination of a vectorized
sequence function and rep. It uses a .Internal to do
the job well. (This is a case where the individual sequences
typically have length one or zero.)
> .Internal(merge(rep(1:3, c(3,0,5)), rep(1:4, c(2,2,3,2)), T, T))
$xi
[1] 1 1 2 2 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8
$yi
[1] 1 2 1 2 1 2 5 6 7 5 6 7 5 6 7 5 6 7 5 6 7
$x.alone
integer(0)
$y.alone
integer(0)
sequence and rep produce complementary outputs, except in the nvec[i]==0 case.
> rep(1:3, c(5,2,7)) # identifies group
[1] 1 1 1 1 1 2 2 3 3 3 3 3 3 3
> sequence(c(5,2,7)) # which in group
[1] 1 2 3 4 5 1 2 1 2 3 4 5 6 7
----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146
"All statements in this message represent the opinions of the author and do
not necessarily reflect Insightful Corporation policy or position."
More information about the R-devel
mailing list