Hi, Dear, I have a problem for the new version 2.0 of R When I put this code in it give me the error: uis$ivhx3[uis$ivhx>0] <- 1*(uis$ivhx==3) Error: NAs are not allowed in subscripted assignments but this would happen in version 1.91 there are missing data in the data set and it is represented as NA the data set can be find on line at the ucla web actually this is a example from its web site the c code is at https://svn.r-project.org/R/trunk/src/main/subassign.c : if(length(y) > 1) for(i = 0; i < n; i++) if(INTEGER(indx)[i] == NA_INTEGER) error("NAs are not allowed in subscripted assignments"); So maybe we need get rid of this conditional code. Best Wishes Ku
about the subscript assignment porblem
2 messages · kh zu, Thomas Lumley
On Tue, 30 Nov 2004, kh zu wrote:
Hi, Dear, I have a problem for the new version 2.0 of R When I put this code in it give me the error: uis$ivhx3[uis$ivhx>0] <- 1*(uis$ivhx==3) Error: NAs are not allowed in subscripted assignments but this would happen in version 1.91
What would happen? In version 1.9.0 (I don't have a 1.9.1 lying around)
you get a warning if any of the subscripts are FALSE
> x<-1:3
> y<-7:9
> x[c(TRUE,NA,FALSE)]<-y
Warning message:
number of items to replace is not a multiple of replacement length
and if all the subscripts are TRUE or NA the NAs are treated as FALSE
> x<-1:3
> y<-7:9
> x[c(TRUE,NA,TRUE)]<-y
> x
[1] 7 2 9
The change was largely motivated by numerical indices, where the problem
is worse. In particular if x is 1,2,3, i is 1, NA, 2 and y is 7,8,9,
should
x[i] <- y
set the second element of x to 8 or 9? The answer was different for
vectors and matrices in 1.9.1.
It was clearly a deliberate change, not a mistake (it's hard to see how it
could have happened accidentally, and it was documented), and the previous
behaviour was wrong.
-thomas