Skip to content
Prev 164923 / 398503 Next

Problem assigning "NA" as a level name in a list

Cliff Behrens wrote:
Relying on a 3rd party package is not kosher either... Whatever did
list("NA"=2)  or l <- list(2); names(l) <- "NA" do to you?
Anyways....  As I thought:

Remember that NA is a reserved word. You get the same kind of reaction 
if you name an element "for" or "in". It denotes that you need to quote 
the name for indexing with $:

 > names(l) <- "NA"
 > l$NA
Error: unexpected numeric constant in "l$NA"
 > l$`NA`
[1] 2
 > l$"NA"
[1] 2
 > l[["NA"]]
[1] 2
 > names(l)
[1] "NA"