[R] Newbie problem with read.table
Marc Schwartz
MSchwartz at mn.rr.com
Wed Oct 12 14:48:53 CEST 2005
On Wed, 2005-10-12 at 14:31 +0200, Jan Conrad wrote:
> Hi R,
> I have a seemingly simple problem. I have a table in following format
> (tab seperated)
>
> Njets NBjets NElec NMuon Meff HT HT3j HE Aplan
> Plan
> 1 4 3 2 0 366.278 253.642 87.7473 1385
> 0.0124566 0.376712
> 2 3 1 1 0 235.19 157.688 18.2852
> 574.253 0.00064187 0.00528814
>
> I read in with:
>
> > ttbar<-read.table("test2.dat",header=TRUE)
>
>
> > ttbar
> Njets NBjets NElec NMuon Meff HT HT3j HE Aplan
> 1 4 3 2 0 366.278 253.642 87.7473 1385.000 0.01245660
> 2 3 1 1 0 235.190 157.688 18.2852 574.253 0.00064187
> Plan
> 1 0.37671200
> 2 0.00528814,
>
> i.e.. the table is split after 9 variables. How come ?
>
> Thanks,
> Jan
As per ?read.table, the default delimiter is 'sep = ""', which is any
"whitespace".
Hence, if your file is tab delimited, you need to modify your call to:
ttbar <- read.table("test2.dat", header = TRUE, sep = "\t")
HTH,
Marc Schwartz
More information about the R-help
mailing list