David Studer
2013-Jan-21 15:35 UTC
[R] missing values are not allowed in subscripted assignments of data frames
Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130121/317d3f7b/attachment.pl>
S Ellison
2013-Jan-21 15:42 UTC
[R] missing values are not allowed in subscripted assignments of data frames
> 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... ?Two things to check: Are there matches to data$commNo==786 ? And is commNo numeric, character or factor? ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
arun
2013-Jan-21 16:23 UTC
[R] missing values are not allowed in subscripted assignments of data frames
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.
David Winsemius
2013-Jan-21 17:12 UTC
[R] missing values are not allowed in subscripted assignments of data frames
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
arun
2013-Jan-21 17:37 UTC
[R] missing values are not allowed in subscripted assignments of data frames
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.