Consider the following:
set.seed(42)
X <- matrix(runif(40),10,4)
colnames(X) <- c("a","b","a:x","b:x") # Imitating the output
# of model.matrix().
D1 <- as.data.frame(X)
D2 <- data.frame(X)
names(D1)
[1] "a" "b" "a:x" "b:x"
names(D2)
[1] "a" "b" "a.x" "b.x"
The names of D2 are syntactically valid; those of D1 are not.
Why should I have expected this phenomenon? :-)
The as.data.frame() syntax seems to me much more natural for converting
a matrix to a data frame, yet it doesn't get it quite right, sometimes,
in respect of the names.
Is there some reason that as.data.frame() does not apply make.names()?
Or was this just an oversight?
cheers,
Rolf Turner
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.