Skip to content
Back to formatted view

Raw Message

Message-ID: <1330220413219-4421439.post@n4.nabble.com>
Date: 2012-02-26T01:40:13Z
From: Rui Barradas
Subject: Dealing with NAs in C
In-Reply-To: <1330216869715-4421377.post@n4.nabble.com>

Hello,

See section 5.10.3 of the R-exts.pdf.

There are macros ISNA(x) and ISNAN(x) (only for 'double') and constants
NA_INTEGER, NA_REAL,
 NA_LOGICAL and NA_STRING.

> I am currently converting a lot of R code to C in order to make it more
> efficient. A lot of the data involves NAs. As
> the data is mainly integers > 0, I am just setting all NAs to 0 then
> sending it to the C code then resetting them to
> NAs again after the C program is done, to be compatible with the rest of
> the R code.

In a C function you could use

int x;

if(x == NA_INTEGER){
    // process an integer NA
}

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Dealing-with-NAs-in-C-tp4421377p4421439.html
Sent from the R help mailing list archive at Nabble.com.