[R] representing NULL values in a vector
Duncan Murdoch
murdoch.duncan at gmail.com
Mon Sep 6 13:00:04 CEST 2010
On 06/09/2010 1:00 AM, rajeshj at cse.iitm.ac.in wrote:
> Hi,
>
> I have a vector who contents should look like this,
>
> "c" "d" NULL "e" "f" etc
> or
> 4 5 6 NULL 7 8 9
>
> how can I represent the null value?
As others have said, you probably want NA rather than NULL. If you
really want NULL, then use a list (a generic vector). So
x <- list("c", "d", NULL, "e", "f")
y <- list(4,5,6,NULL, 7,8,9)
You need to be careful when setting values, because
y[[1]] <- NULL
will *remove* element 1, not set it to NULL. To set it to NULL, use
y[1] <- list(NULL)
Duncan Murdoch
More information about the R-help
mailing list