[Rd] matrices with names
William Dunlap
wdunlap at tibco.com
Thu Jul 20 18:56:18 CEST 2017
How should R deal with matrices that have a 'names' attribute? S (and S+)
did not allow an object to have both dims and names but R does. However,
some R functions copy the dims but not the names to the returned value and
some copy both. I don't see a pattern to it. Is there a general rule for
when the names on a matrix should be copied to the return value of a
function?
> x <- matrix(11,1,1)
> names(x)<-"One"
> dput(x)
structure(11, .Dim = c(1L, 1L), .Names = "One")
> dput(log2(x))
structure(3.4594316186373, .Dim = c(1L, 1L), .Names = "One")
> dput(pchisq(x,8))
structure(0.798300801297471, .Dim = c(1L, 1L), .Names = "One")
> dput(x+1)
structure(12, .Dim = c(1L, 1L))
> dput(x > 3)
structure(TRUE, .Dim = c(1L, 1L))
> dput(!x)
structure(FALSE, .Names = "One", .Dim = c(1L, 1L))
> dput(-x)
structure(-11, .Dim = c(1L, 1L), .Names = "One")
> dput(0-x)
structure(-11, .Dim = c(1L, 1L))
The binary operators don't copy, unary operators do copy, and many other
low-level functions do copy.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
[[alternative HTML version deleted]]
More information about the R-devel
mailing list