[R] Odd behaviour of R 2.00

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Nov 14 11:26:48 CET 2004


"Hiroto Miyoshi" <h_m_ at po.harenet.ne.jp> writes:

> Dear R users
> 
> I have a data frame containing character and numeric variables, whose
> name is seishin.  When I tried to assign NA to "" in the data frame, R, 2.00
> showed an error message, such as
> 
> > seishin[seishin==""]<-NA
> Error: NAs are not allowed in subscripted assignments
> 
> This did not happen under R 1.9.0.
> 
> More oddly,
> The following commands work just fine under R 2.0.0
> > a<-1:10
> > b<-letters[1:10]
> > b[3]<-""
> > c<-data.frame(cbind(a,b))
> > c[c==""]<-NA
> 
> Why is this so?

It is the NA pattern on the left hand side that matters. Does it help
to use 

seishin[!is.na(seishin) & seishin==""]<-NA

?

(For atomic vectors you could also use %in% instead of ==, but this
doesn't work with data frames.)

> And how can I assign NA to "" data.framewise in seishin data.frame?

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list