"[<-" 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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 andprevious> 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
As Brian pointed out my comments were regarding [ ] not [<-. I guess I need another cup of coffee this morning.>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.I have played with this some and the answer is not obvious. There are some attributes it would be nice to keep and others it would be better to strip. My tframe attribute has to be consistent with the first dimension of the matrix, so it either has to be modified when the dim is modified or it has to be stripped so that there is not conflicting information. I have learned to live with the latter. On the subject of [ ], it sure would be nice if this supported drop as a vector logical (e.g. drop=c(T,F,T) ) so that drop could be specified dimension wise for arrays. Paul -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Date: Wed, 18 Nov 1998 18:22:23 +0100 > From: Martyn Plummer <plummer@iarc.fr> > To: Paul Gilbert <pgilbert@bank-banque-canada.ca> > CC: Prof Brian Ripley <ripley@stats.ox.ac.uk>, R-devel<R-devel@stat.math.ethz.ch>> Subject: Re: "[" not "[<-" > > Paul Gilbert wrote: > > > > Brian Ripley writes > > >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. > > > > I have played with this some and the answer is not obvious. There are some > > attributes it would be nice to keep and others it would be better to strip.My> > tframe attribute has to be consistent with the first dimension of thematrix, so> > it either has to be modified when the dim is modified or it has to bestripped> > so that there is not conflicting information. I have learned to live withthe> > latter. > > Couldn't you use the object-oriented features of R? For objects of class > "foo", subsetting can be done using the "[.foo" function. Attributes can be > saved > before passing the data on to NextMethod (which would strip attributes it > doesn't > know about). Then the saved attributes could be restored, possibly in a > modified > form, if the object is still of class "foo". > > I had assumed that this was the logic of subsetting, but it would be nice > if someone could confirm this. >More or less (but I can only confirm my understanding of this). The saving is not in fact needed. For example, "[.factor" does y <- NextMethod("[") attr(y, "contrasts") <- attr(x, "contrasts") levels(y) <- levels(x) etc in S. In R it does only attr(y, "levels") <- attr(x, "levels") (and I think that is now a bug: it should preserve attr(x, "contrasts")). I was referring to the default: Paul's example had no class. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Gilbert <pgilbert@bank-banque-canada.ca> writes:> > z <- data[10:90,] > > attributes(z) > $dim > [1] 81 3 > $tframe > [1] 1981.50 2006.25 4.00 > > Splus:> > attributes(z) > $dim: > [1] 81 3It's a one-line change to get Splus behaviour. Anoyone think of a reason *not* to do that?? -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._