On Feb 3, 2010, at 3:08 PM, 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.

You can set the check.names argument to FALSE, but I would strongly advise 
against this.

Depending upon the context of use, a-1 will be interpreted by R as the value(s) 
in object 'a' minus 1.

This is why there are legal object names/characters in R and it checks for them 
when importing data.

To get around the above default behavior, you can use quotes and such, but you 
are asking to get bitten by hard to find errors in your code if you proceed.

Caveat Emptor.

HTH,

Marc Schwartz

______________________________________________
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.

Reply via email to