more on "[<-"

Prof Brian Ripley Prof Brian Ripley <ripley@stats.ox.ac.uk>
Wed, 18 Nov 1998 16:21:45 +0000 (GMT)


Paul,

you are nowhere using "[<-"!  You are using "[" on a vector, and the dim
attribute is not being stripped, only your own "tframe" attribute.

It is clear to me that "[<-" should not change attributes, as it does not:

data <- matrix(rnorm(300),100,3)
attr(data, "tframe") <- c(1981.50, 2006.25 ,   4.00)
data[10:90,1] <- rnorm(81)
attributes(data)

on any of these, but it is less clear what [] should do. As it is not
clear if the attributes apply to the whole object only, I suspect stripping
is right.

Brian

> From: Paul Gilbert <pgilbert@bank-banque-canada.ca>

> "[<-" in R 0.63 does not appear to strip attributes, whereas Splus and 
previous
> versions of R did.
> 
> Paul
> _____
> 
> R 0.63:
> >  data <- matrix(rnorm(300),100,3)
> >  attr(data, "tframe") <- c(1981.50, 2006.25 ,   4.00)
> > attributes(data)
> $dim
> [1] 100   3
> $tframe
> [1] 1981.50 2006.25    4.00
> > z <- data[10:90,]
> > attributes(z)
> $dim
> [1] 81  3
> $tframe
> [1] 1981.50 2006.25    4.00
> 
> Splus:
> >   data <- matrix(rnorm(300),100,3)
> >  attr(data, "tframe") <- c(1981.50, 2006.25 ,   4.00)
> > attributes(data)
> $dim:
> [1] 100   3
> $tframe:
> [1] 1981.50 2006.25    4.00
> > z <- data[10:90,]
> > attributes(z)
> $dim:
> [1] 81  3
> 

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