[R] Odd behaviour of R 2.00

Hiroto Miyoshi h_m_ at po.harenet.ne.jp
Sun Nov 14 12:39:31 CET 2004


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.
--------------------------------
Hiroto Miyoshi
h_m_ at po.harenet.ne.jp
----- Original Message ----- 
From: "Peter Dalgaard" <p.dalgaard at biostat.ku.dk>
To: "Hiroto Miyoshi" <h_m_ at po.harenet.ne.jp>
Cc: <r-help at stat.math.ethz.ch>
Sent: Sunday, November 14, 2004 7:26 PM
Subject: Re: [R] Odd behaviour of R 2.00


> "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?
>
>
> (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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
>




More information about the R-help mailing list