Hi,
I run into the following problem:
> data(iris)
> as.array(iris[,-5])
Error in "dimnames<-.data.frame"(`*tmp*`, value = list(c("Sepal.Length", :
invalid dimnames given for data frame
> as.array(as.matrix(iris[,-5]))
When trying to convert numeric data frame to an array. Conversion to matrix
works just fine, but array crashes. Since documentation for "as.array" says
its argument has to be "an R object" than it should work for data frames as
well.
Closer examination shows that "as.array" code with [150 x 4] data frame as
input, does the following:
# line of code effect
1 if (is.array(x)) return(x) is.array is false
2 n <- names(x) "names" return a
vector of 4 column names
3 dim(x) <- length(x) dim(x) before is [150 x 4];
length(x) is 4; dim(x) after is still [150 x 4]
4 if (length(n)) dimnames(x)<-list(n) list(n) is a list containing 1
vector with 4 strings; attempt to set it as dimnames to [150x4] object
fails
5 return(x)
If this is a bug and not poorly documented feature, than changing line 2 to
"n <- dimnames(x)" seem to work for this example.
Jarek
=====================================\====
Jarek Tuszynski, PhD. o / \
Science Applications International Corporation <\__,|
(703) 676-4192 "> \
[EMAIL PROTECTED] ` \
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html