From Prof Brian Ripley <ripley@stats.ox.ac.uk>  Wed Jan 26 17:26:50 2000
From: Prof Brian Ripley <ripley@stats.ox.ac.uk> (Prof Brian Ripley)
Date: Wed, 26 Jan 2000 17:26:50 +0000 (GMT)
Subject: data.frame[1,1]<- differs from data.frame[[1]][1]<- (PR#403)
Message-ID: <200001261726.RAA23501@toucan.stats.ox.ac.uk>


> From: jens.oehlschlaegel-akiyoshi@mdfactory.de
> Date: Wed, 26 Jan 2000 17:24:05 +0100 (MET)
> 
> 
> I observed the following difference:
> 
> > ddd <- data.frame(a=1:3, b=1:3)
> 
> # assignment of 'X' silently ignored
> > ddd[1,1] <- 'X'
> > is.factor(ddd[[1]])
> [1] FALSE
> > ddd
>   a b
> 1 1 1
> 2 2 2
> 3 3 3

actually it assigns as.numeric(factor("X")), which is 1.

> # assignment of 'X' not ignored
> > ddd[[1]][1] <- 'X'
> > is.factor(ddd[[1]])
> [1] TRUE
> > ddd
>   a b
> 1 X 1
> 2 2 2
> 3 3 3
> 

Here is my solution: line 488 in dataframe.R, in "[<-.data.frame"

## careful, as.data.frame turns things into factors.
##    value <- as.data.frame(value)
    if(!is.list(value) && (missing(j) || !missing(i))) { # [i, ] or [i,j]
        value <- matrix(value, n, p)
        dimv <- c(n, p)
        value <- split(value, col(value))
    } else {
        value <- as.data.frame(value)
        dimv <- dim(value)
    }

It covers the same cases as the prototype, but is a kludge, of course.

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


data.frame[1,1]<- differs from data.frame[[1]][1]<- (PR#403)
Prof Brian Ripley