[R] Problem assigning "NA" as a level name in a list
Cliff Behrens
cliff at research.telcordia.com
Tue Dec 16 19:28:07 CET 2008
Sorry...I didn't realize that there were such distinct lines drawn
around core vs contributed packages. I merely thought that r-help put
those with questions in touch with others who might have used or
authored a package and experienced the same problem. I didn't intend to
make more work for you or anyone else on this list. In fact, I was
merely trying to be thorough and exact, including a note with the
version of R and the OS I am running. I have no idea what packages
others have installed in their R environments. For future reference, am
I to assume that no contributed packages should be implicated in
resolving a problem?
Peter Dalgaard wrote:
> Cliff Behrens wrote:
>> Peter,
>>
>> I've inserted response inline below:
>>
>> Cliff
>>
>> Peter Dalgaard wrote:
>>> Cliff Behrens wrote:
>>>> Peter,
>>>>
>>>> OK...here is reproducible, self-contained code:
>>>>
>>>> library(gregmisc)
>>>
>>> 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?
>>>
>> I'm not sure what you mean by "3rd party?" I downloaded this package
>> from the CRAN site where I get all others. I don't understand your
>> question.
>
> 3rd party means that you didn't write it and neither did I/we. You are
> requesting people to help you, yet expecting that they go out of their
> way to install a package first. (As it happens, I really don't have
> gregmisc on this machine.) You could easily have created an example of
> a list with "NA" as a name, but that would of course have been work
> for you rather than for people on the list.
>
>
>
>>>> columnNames <- c("A","B","C","D","N","a","b","c")
>>>> namePerms<-
>>>> permutations(length(columnNames),2,columnNames,repeats=TRUE)
>>>> nameList <- paste(namePerms[,1],namePerms[,2],sep="")
>>>> dataList <- lapply(1:length(nameList), function(level) {})
>>>> names(dataList)<- nameList ## The "NA" is interpreted that the
>>>> name is missing for one list in dataList
>>>>
>>>> If you inspect the contents of dataList, you will find the
>>>> following showing that the name "NA" is treated differently:
>>>
>>> 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 $:
>>>
>> I thought that since all of the names in namesList were type char,
>> there was no need to enclose these in quotation marks.
>
> That's not the point. It works fine, it is just that the output is
> showing you how to access the element afterwards.
>
>>> > 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"
>>>
>>>> ......
>>
>>
>
>
More information about the R-help
mailing list