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

arun smartpink111 at yahoo.com
Mon Jan 21 18:37:40 CET 2013


Hi,

If 'commNo` is factor.
set.seed(5)
data1<-data.frame(commNo=sample(786:789,10,replace=TRUE),Col2=rnorm(10,10))

set.seed(5)
data2<-data.frame(commNo=sample(c(786:789,NA),10,replace=TRUE),Col2=rnorm(10,10))

data4<-within(data1,{commNo<-factor(commNo)})
data4[data4$commNo==786, "commNo"]<-"Name of the Community"
#Warning message:
#In `[<-.factor`(`*tmp*`, iseq, value = c("Name of the Community",  :
  #invalid factor level, NAs generated 

#you get a warning message and 786 get replaced by NA.

In the case of :
 data2[data2$commNo==786, "commNo"]<-"Name of the Community"
#Error in `[<-.data.frame`(`*tmp*`, data2$commNo == 786, "commNo", value = "Name of the Community") : 
 # missing values are not allowed in subscripted assignments of data frames 

#The error message is similar to the ones that you got.
A.K.




----- Original Message -----
From: David Studer <studerov at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Monday, January 21, 2013 10:35 AM
Subject: [R] missing values are not allowed in subscripted assignments of data frames

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"

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... ?

Can anyone help please?

Thank you very much!

David

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list