[R] Header in read.table() function

Peter Alspach Peter.Alspach at plantandfood.co.nz
Wed Feb 3 22:25:14 CET 2010


Tena koe Paul

a-1 is not valid syntax in a name hence the conversion.  See ?make.names
for more information.  You could change the names after importing with
read.table; e.g.

names(whatever)[2] <- 'a-1'

but you may regret it later.

HTH .....

Peter Alspach

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Paul Evans
> Sent: Thursday, 4 February 2010 10:09 a.m.
> To: r-help at stat.math.ethz.ch
> Subject: [R] Header in read.table() function
> 
> 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.
> 
> 
>       
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.
> 



More information about the R-help mailing list