[R] Odd behaviour of R 2.00

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Nov 14 13:27:57 CET 2004


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

> Dear  Professor Dalgaard
> 
> > It is the NA pattern on the left hand side that matters. Does it help
> > to use
> >
> > seishin[!is.na(seishin) & seishin==""]<-NA
> >
> > ?
> 
> Yes!  the above line worked perfectly.
> But why? To me, !is.na(seishin) & seishin=="" seems redundant.
> If you could explain this, it would be greatly appreciated.
> Thank you.

It's due to this change (do check the NEWS file when things change
unexpectedly...):
 
    o   Subassignments involving NAs and with a replacement value of
        length > 1 are now disallowed.  (They were handled
        inconsistently in R < 2.0.0, see PR#7210.)  For data frames
        they are disallowed altogether, even for logical matrix indices
        (the only case which used to work).

Now, I'm getting slightly confused here, since there appears to be
exceptions:

> str(c)
`data.frame':   10 obs. of  2 variables:
 $ a: Factor w/ 10 levels "1","10","2","3",..: 1 3 4 5 6 NA 8 9 10 2
 $ b: Factor w/ 9 levels "","a","b","e",..: 2 3 1 NA 4 5 6 7 8 9
> c[c==""]<-NA
> str(c)
`data.frame':   10 obs. of  2 variables:
 $ a: Factor w/ 10 levels "1","10","2","3",..: 1 3 4 5 6 NA 8 9 10 2
 $ b: Factor w/ 9 levels "","a","b","e",..: 2 3 NA NA 4 5 6 7 8 9

> version
         _
platform i686-pc-linux-gnu
arch     i686
os       linux-gnu
system   i686, linux-gnu
status
major    2
minor    0.0
year     2004
month    10
day      04
language R

Also:

> aq <- airquality
> aq[aq==5] <- 98765432
> aq[aq==97] <- 98765432
Error: NAs are not allowed in subscripted assignments

(difference being that 97 occurs in columns with NA's and 5 does not)

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