[Rd] R C API resize matrix
Simon Urbanek
@|mon@urb@nek @end|ng |rom R-project@org
Mon Jun 17 16:54:15 CEST 2019
Matrix is just a vector with the dim attribute. Assuming it is not referenced by anyone, you can set any values to the dim attribute. As for the vector, you can use SET_LENGTH() to shorten it - but I'm not sure how official it is - it was originally designed to work, but there were abuses of TRUELENGTH so not sure where we stand now (shortened vectors used to fool the garbage collector as far as object sizes go). I wouldn't do it unless you're dealing with rally huge matrices.
Cheers,
Simon
> On Jun 14, 2019, at 5:31 PM, Morgan Morgan <morgan.emailbox using gmail.com> wrote:
>
> Hi,
>
> Is there a way to resize a matrix defined as follows:
>
> SEXP a = PROTECT(allocMatrix(INTSXP, 10, 2));
> int *pa = INTEGER(a)
>
> To row = 5 and col = 1 or do I have to allocate a second matrix "b" with
> pointer *pb and do a "for" loop to transfer the value of a to b?
>
> Thank you
> Best regards
> Morgan
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list