From rdpeng at gmail.com  Wed May  5 18:16:12 2010
From: rdpeng at gmail.com (Roger Peng)
Date: Wed, 5 May 2010 12:16:12 -0400
Subject: [Rd] Generate NA of specified type
In-Reply-To: <h2gf8e6ff051005050857tfe7d7566m797b3abbad5f429c@mail.gmail.com>
References: <h2gf8e6ff051005050857tfe7d7566m797b3abbad5f429c@mail.gmail.com>
Message-ID: <h2h66f3bd911005050916nf9007da5h96d64ad4430c7de2@mail.gmail.com>

What about NAof <- function(x) as(NA, class(x))?

-roger

On Wed, May 5, 2010 at 11:57 AM, Hadley Wickham <hadley at rice.edu> wrote:
> Hi all,
>
> Is there an existing function that provides the correct type of
> missing value for a given vector? e.g.
>
> NAof(1:3) # NA_integer_
> NAof(pi) # NA_real_
> NAof("a") # NA_character_
> NAof(T) # NA
>
> ?
>
> Thanks,
>
> Hadley
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Roger D. Peng  |  http://www.biostat.jhsph.edu/~rpeng/



[Rd] Generate NA of specified type
Roger Peng