[Rd] 1-based arrays and copying vectors
Lopaka Lee (Rob)
rlee at inverness.fpcc.net
Mon Jun 20 00:53:21 CEST 2005
I'm interfacing to C code that uses 1-based indexing on arrays -- it
ignores the zeroth element. Thus, input vectors from R must be moved up
one, and output arrays must be moved down one.
What is the best way to deal with this using R internal code?
My current approach is:
For an input R vector of length n, allocate a new vector(v) of length n+1
and copy input into v[1] to v[1+n]. Call with new vector.
For an output array(a) of length n, allocate a new vector of length n-1
and copy a[1] to a[n] into v[0] to v[n-1].
If this is the best approach, is there an idiom for copying vectors?
-Lopaka
More information about the R-devel
mailing list