Paul Evans wrote:
Hi,
I wanted to read in a table that had hyphens in the header / column
names. When I read it in however, it replaces the hyphens with a dot.
Which parameter in the read.table function do I need to set to change
this behaviour? Example code: jm <- matrix(1:4,2,2) rownames(jm) <-
c('a','b') colnames(jm) <- c('a-1','a-2')
write.table(jm,'tjm.out',row.names=T,col.names=T,sep='\t')
mm <- read.table('tjm.out',row.names=1,header=T,sep='\t',colClasses =
"character") print(mm) a.1 a.2 a 1 3 b 2 4 I would like 'a-1'
'a-2' in the header and not a.1 & a.2 thanks.
read.table is trying to create a data.frame. If you're data.frame had a
column named 'a', what should
mm$a-1
do? Print out mm$a-1, or subtract 1 from mm$a ? If you want your
original matrix back (i.e., object of class matrix), you could just use
save/load functions.
I don't think it's possible to have a data.frame with those names, just
as you can't do, say:
a-1 <- 1:10
Erik
I
______________________________________________
R-help@r-project.org mailing list
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.