[R] Putting a NULL in a list (as cannot pass NA to C++)
Charles C. Berry
cberry at tajo.ucsd.edu
Mon Dec 3 22:10:39 CET 2007
On Mon, 3 Dec 2007, Rees, David wrote:
> Hi,
>
> If I do the following I can have a NULL in a list
>
>> x <- list( 1, list(3,NULL,4), 5 )
>> x
> [[1]]
> [1] 1
>
> [[2]]
> [[2]][[1]]
> [1] 3
>
> [[2]][[2]]
> NULL
>
> [[2]][[3]]
> [1] 4
>
>
> [[3]]
> [1] 5
>
> This is a good thing for me as it can be passed through into C++ where I
> can know the value is missing. (Can't seem to detect a NA from C++ for
> some reason. There is RF_isNull in the API but no RF_isNA that I can
> find!)
Is this what you were looking for?
Writing R Extensions
6.4 Missing and IEEE special values
A set of functions is provided to test for NA, Inf, -Inf and NaN. These
functions are accessed via macros:
ISNA(x) True for R's NA only
ISNAN(x) True for R's NA and IEEE NaN
R_FINITE(x) False for Inf, -Inf, NA, NaN
HTH,
Chuck
p.s. grep '<something>' within R's include directory can quickly resolve
questions like this.
>
> Is it possible to put a null in an already created list. e.g. now do
>
>> x[[2]][[2]] <- NULL
>> x
> [[1]]
> [1] 1
>
> [[2]]
> [[2]][[1]]
> [1] 3
>
> [[2]][[2]]
> [1] 4
>
>
> [[3]]
> [1] 5
>
>
> But x[[2]][[2]] has been deleted.
>
> Many thanks
>
> Regards,
> David
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
More information about the R-help
mailing list