Good morning,
suppose the following:
m <- round(matrix(rnorm(16), ncol=4), 3)
a <- rev(c(0.01, 0.025, 0.05, 0.1))
rownames(m) <- a
colnames(m) <- c("0.25,0.75", "0.4,0.6",
"0.1,0.9", "0.4,0.9")
m
0.25,0.75 0.4,0.6 0.1,0.9 0.4,0.9
0.1 1.034 -0.119 -1.213 0.619
0.05 0.035 1.074 0.525 1.671
0.025 -1.687 0.960 0.324 -0.170
0.01 0.906 1.642 0.557 -2.224
and now write.table says:
write.table(m)
"X0.25.0.75" "X0.4.0.6" "X0.1.0.9"
"X0.4.0.9"
"0.1" "1.034" "-0.119" "-1.213"
"0.619"
"0.05" "0.035" "1.074" "0.525"
"1.671"
"0.025" "-1.687" "0.96" "0.324"
"-0.17"
"0.01" "0.906" "1.642" "0.557"
"-2.224"
If one writes 'm' into a file and reads it using read.table:
read.table("dummy")
X0.25.0.75 X0.4.0.6 X0.1.0.9 X0.4.0.9
0.1 1.034 -0.119 -1.213 0.619
0.05 0.035 1.074 0.525 1.671
0.025 -1.687 0.960 0.324 -0.170
0.01 0.906 1.642 0.557 -2.224
the colnames are incorrect. Do I miss something?
Torsten
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 6 Dec 2000, Torsten Hothorn wrote:> > Good morning, > > suppose the following: > > m <- round(matrix(rnorm(16), ncol=4), 3) > a <- rev(c(0.01, 0.025, 0.05, 0.1)) > rownames(m) <- a > colnames(m) <- c("0.25,0.75", "0.4,0.6", "0.1,0.9", "0.4,0.9") > m > 0.25,0.75 0.4,0.6 0.1,0.9 0.4,0.9 > 0.1 1.034 -0.119 -1.213 0.619 > 0.05 0.035 1.074 0.525 1.671 > 0.025 -1.687 0.960 0.324 -0.170 > 0.01 0.906 1.642 0.557 -2.224 > > and now write.table says: > > write.table(m) > "X0.25.0.75" "X0.4.0.6" "X0.1.0.9" "X0.4.0.9" > "0.1" "1.034" "-0.119" "-1.213" "0.619" > "0.05" "0.035" "1.074" "0.525" "1.671" > "0.025" "-1.687" "0.96" "0.324" "-0.17" > "0.01" "0.906" "1.642" "0.557" "-2.224" > > If one writes 'm' into a file and reads it using read.table: > > read.table("dummy") > X0.25.0.75 X0.4.0.6 X0.1.0.9 X0.4.0.9 > 0.1 1.034 -0.119 -1.213 0.619 > 0.05 0.035 1.074 0.525 1.671 > 0.025 -1.687 0.960 0.324 -0.170 > 0.01 0.906 1.642 0.557 -2.224 > > the colnames are incorrect. Do I miss something?Yes. write.table converts to a data frame. Try x <- data.frame(m, check.names=FALSE) write.table(x) to give it a data frame in the first place. The help says: x: the object to be written, typically a data frame. If not, it is attempted to create one from it. and the names get converted during that process to valid names. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi Thorsten! On 06-Dec-00 Torsten Hothorn wrote:> > Good morning, > > suppose the following: > > m <- round(matrix(rnorm(16), ncol=4), 3) > a <- rev(c(0.01, 0.025, 0.05, 0.1)) > rownames(m) <- a > colnames(m) <- c("0.25,0.75", "0.4,0.6", "0.1,0.9", "0.4,0.9") > m > 0.25,0.75 0.4,0.6 0.1,0.9 0.4,0.9 > 0.1 1.034 -0.119 -1.213 0.619 > 0.05 0.035 1.074 0.525 1.671 > 0.025 -1.687 0.960 0.324 -0.170 > 0.01 0.906 1.642 0.557 -2.224 > > and now write.table says: > > write.table(m) > "X0.25.0.75" "X0.4.0.6" "X0.1.0.9" "X0.4.0.9"You can see write.table is the "bad guy" here, already giving incorrect colnames. If you use write.table(as.data.frame(m)) everything is working fine. cu Detlef -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> > Date: 06 Dec 2000 11:05:32 +0100 > > Prof Brian Ripley <ripley@stats.ox.ac.uk> writes: > > > and the names get converted during that process to valid names. > ^^^^^^^^^^^ > > Just to pick a nit: Could we make a habit of distinguishing between > "names" and "identifiers"? The latter being the syntactical term in > the R language, briefly the names that you don't need to use get() to > access. "123" and "Height in cm" are valid names, but not valid > identifiers.The argument is called `check.names', and has description check.names: if `TRUE' then the names of the variables in the data frame are checked to ensure that they are valid variable names. If necessary they are adjusted (by `make.names') so that they are. So `make.names' should be renamed as `make.identifiers'. That is described as make.names package:base R Documentation Make Legal R Names Out of Strings Description: Make legal R names out of every `names[i]' string. Invalid characters are translated to `"."'. More plausibly, you are proposing a new distinction .... -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._