[R] Odd behaviour of R 2.00
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun Nov 14 13:27:48 CET 2004
On Sun, 14 Nov 2004, Hiroto Miyoshi wrote:
> 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.
Without it, your logical matrix index contains NA. What do you intend
that to do? Do you replace the corresponding element or not? You don't
know, so perhaps you set it to NA, whatever the rhs? And do you use up a
value on the rhs or not (not relevant if as here you are recycling a
single value, except that you need to know how many times to recycle it)?
Prior to 2.0.0, R behaved inconsistently (both within itself and with S)
with NA indices in assignments, so now we force the user to say what he
intended. This has picked up quite a number of errors.
I do think this would be cleaner and faster using a loop over columns,
especially as you probably have factors in the data frame. Read the code
of "[<-.data.frame" if you don't see that.
> 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,
>>> showed an error message, such as
>>> 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
>>> 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
>> PLEASE do read the posting guide!
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help