[R] Accessing row and col names of SEXP objects
Whit Armstrong
Whit.Armstrong at tudor.com
Wed Dec 17 20:03:53 CET 2003
Can someone lend me a hand with extracting the dimnames from a SEXP? I've
looked through R-exts, but I couldn't find an example.
Here is the code I'm using to grab the jth column name and print it, but the
colnames I'm getting are garbage.
None of the following are working.
void printInfo(SEXP ts) {
int j;
for (j=0; j<col; j++) {
printf("%s\n",CHAR(STRING_ELT(GetColNames(ts), j)));
printf("%s\n",CHAR(VECTOR_ELT(GetColNames(ts), j)));
printf("%s\n",CHARACTER_DATA(STRING_ELT(GetColNames(ts), j)));
printf("%s\n",CHARACTER_DATA(VECTOR_ELT(GetColNames(ts), j)));
}
}
Here is the object I'm passing in:
tmp <- matrix(rnorm(100),ncol=5)
colnames(tmp) <- c("tmp","a","b","c","d")
rownames(tmp) <- 1:100
.Call("printInfo",tmp)
Thanks for your help.
Regards,
Whit
More information about the R-help
mailing list