[R] how to check if an attribute exists

Peter Langfelder peter.langfelder at gmail.com
Thu Feb 3 04:25:33 CET 2011


On Wed, Feb 2, 2011 at 7:22 PM, Nick Matzke <matzke at berkeley.edu> wrote:
> Oh wait, this basically does it:
>
>> if ("a" %in% attributes(z)$names)
> + print(TRUE)
> [1] TRUE
>
> (but there may be a better way)

If z is a list, you can test

is.null(z$a)

Peter



More information about the R-help mailing list