Converting a data.frame with a nested data.frame to a matrix fails:

x <- structure(list(a = data.frame(letters)),
               class = "data.frame",
               row.names = .set_row_names(26))

as.matrix(x)
#> Error in ncol(xj) : object 'xj' not found

The offending code is here, in the definition of as.matrix.data.frame (source/base/all.R):

    for (j in pseq) {
        if (inherits(X[[j]], "data.frame") && ncol(xj) > 1L)
            X[[j]] <- as.matrix(X[[j]])
        xj <- X[[j]]

It should be ncol(X[[j]]), not ncol(xj). Also, the code would be more generic if it used is.data.frame here instead of inherits(, "data.frame").


Patrick

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to