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

arun smartpink111 at yahoo.com
Mon Jan 21 17:23:19 CET 2013


Hi,

I guess there should be missing values.
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))

data1[data1$commNo==786, "commNo"]<-"Name of the Community"
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

 head(data1,3)
#                 commNo     Col2
#1 Name of the Community 9.397092
#2                   788 9.527834
#3                   789 9.364629

 data3<-data2[complete.cases(data2),]
data3[data3$commNo==786, "commNo"]<-"Name of the Community"
 head(data3,4)
 #                commNo      Col2
#1                   787  9.397092
#2                   789  9.527834
#4                   787  9.714226
#5 Name of the Community 10.138108
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