[R] missing values are not allowed in subscripted assignments of data frames

David Winsemius dwinsemius at comcast.net
Mon Jan 21 18:12:30 CET 2013


On Jan 21, 2013, at 7:35 AM, David Studer wrote:

> Hello everybody!
>
> I am trying to replace community numbers with  community names  
> (character).
> I am using the following code:
>
> data[data$commNo==786, "commNo"]<-"Name of the Community"

data$commNo is probably a factor. As such the equality test will only  
give you expected results with:

> data[data$commNo=='786', "commNo"]<-"Name of the Community"

Or:

> data[as.numeric(as.character(data$commNo)) == 786, "commNo"]<-"Name  
> of the Community"

(It's in section 7 of the RFAQ).



>
> Unfortunately, I get the error message
> missing values are not allowed in subscripted assignments of data  
> frames
>
> However, when I check data$commNo with table(useNA="always") or with
> table(is.na(data$commNo)) it tells me that there are no NA's at  
> all... ?
>
>


David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list