[Rd] 1-based arrays and copying vectors

From: Rob <rlee_at_inverness.fpcc.net>
Date: Sun 19 Jun 2005 - 22:53:21 GMT


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



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Jun 20 08:55:47 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:09 GMT