Re: [Rd] Data table in C

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Fri 17 Nov 2006 - 17:22:16 GMT

"Tom McCallum" <tom.mccallum@levelelimited.com> writes:

> After getting one list done, I am now struggling to form a data frame in C.
>
> I tried to do a list of lists which gives me :
>
> $<NA>
> $<NA>[[1]]
> [1] "BID"
>
> $<NA>[[2]]
> [1] 0.6718
[snip]
>
> and then as.data.frame them in R but this gives me

One approach is to return a named list and then turn that into a data.frame like:

ret <- .Call("yourFunc", ...)
attr(ret, "row.names") <- as.integer(indx) class(ret) <- "data.frame"

In C, you need to create a list (VECSXP) and a character vector (STRSXP) for the names and then put the names on the list.

PROTECT(ret = allocVector(VECSXP, N));
PROTECT(retnames = allocVector(STRSXP, N));

/* fill list and names */

SET_NAMES(ret, retnames);

+ seth



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Nov 18 04:25:19 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 17 Nov 2006 - 20:30:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.