Message-ID: <m2psbmf0on.fsf@ziti.local>
Date: 2006-11-17T17:22:16Z
From: Seth Falcon
Subject: Data table in C
In-Reply-To: <op.ti53ujp0ffxks9@norisk> (Tom McCallum's message of "Fri, 17 Nov 2006 15:55:21 -0000")
"Tom McCallum" <tom.mccallum at 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