Skip to content

more on "[<-"

3 messages · Brian Ripley, Paul Gilbert, Martyn Plummer

#
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
previous

  
    
#
As Brian pointed out my comments were regarding [ ] not [<-. I guess I need
another cup of coffee this morning.
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Paul Gilbert wrote:
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.

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