Skip to content

dimnames usage in ts (PR#1288)

3 messages · tkeitt@ms.cc.sunysb.edu, Peter Dalgaard, Tim Keitt

#
Full_Name: Tim Keitt
Version: 1.4
OS: Linux
Submission from: (NULL) (129.49.19.70)


I think this code in 'ts' is incorrect:

    if (is.matrix(data) || is.data.frame(data)) {
        nseries <- ncol(data)
        ndata <- nrow(data)
        dimnames(data) <- list(NULL, names)
    }

since
[1] "X1"  "X2"  "X3"  "X4"  "X5"  "X6"  "X7"  "X8"  "X9"  "X10"
[[1]]
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"

[[2]]
 [1] "X1"  "X2"  "X3"  "X4"  "X5"  "X6"  "X7"  "X8"  "X9"  "X10"
Error in "dimnames<-.data.frame"(*tmp*, value = list(NULL, names(x))) : 
	invalid dimnames given for data frame
Or else, "dimnames<-.data.frame" has a bug.

T.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
tkeitt@ms.cc.sunysb.edu writes:
...
It doesn't (well, this isn't one...). A data frame must have unique
rownames, so trying to set them to NULL is wrong, as you say. 

The fix would seem to be something like replacing the last line with

if (is.null(dimnames(data)))
        dimnames(data) <- list(NULL, names)
else
        dimnames(data)[[2]] <- name

Did you actually get bitten by this one?
#
On Tue, 2002-01-29 at 15:57, Peter Dalgaard BSA wrote:
Yes. (Sorry if that wasn't clear.) In the past, I could create a
multivariate time series object by passing a dataframe to the 'ts' or
'as.ts' functions --- that no longer works because 'ts' tries to set the
row names to NULL. Unless I'm missing something, the bug is in the 'ts'
function.

Tim