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)> ttbarNjets 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
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, > JanAs 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
On Wed, 12 Oct 2005, 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 ?> options("width")$width [1] 80 says what the width of your console is. Columns beyond this get wrapped gently (not each row by itself) - it can be set different values if you choose - try: ow <- options("width") options(width=40) options("width") ttbar options(ow) options("width") So this is just the print function for data.frame objects doing its unsung job. A very useful function for looking at things when they don't seem to be what you think is str(), which concisely says what the structure of an object is, so str(ttbar) should tell you that it is a data frame of 10 variables and 2 observations.> > Thanks, > Jan > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: Roger.Bivand at nhh.no
Thank you all for your answers. Yes, indeed it was only a printing problem (in fact I had tried the \t option before without sucess). My first interaction with R (and the R help), I must say I am impressed. Best, Jan -----Original Message----- From: Marc Schwartz [mailto:MSchwartz at mn.rr.com] Sent: Wednesday, October 12, 2005 3:14 PM To: Roger.Bivand at nhh.no Cc: Jan Conrad; r-help at stat.math.ethz.ch Subject: Re: [R] Newbie problem with read.table On Wed, 2005-10-12 at 14:56 +0200, Roger Bivand wrote:> On Wed, 12 Oct 2005, 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 HEAplan> > 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 HEAplan> > 1 4 3 2 0 366.278 253.642 87.7473 1385.0000.01245660> > 2 3 1 1 0 235.190 157.688 18.2852 574.2530.00064187> > Plan > > 1 0.37671200 > > 2 0.00528814, > > > > i.e.. the table is split after 9 variables. How come ? > > > options("width") > $width > [1] 80 > > says what the width of your console is. Columns beyond this get > wrapped > gently (not each row by itself) - it can be set different values ifyou> choose - try: > > ow <- options("width") > options(width=40) > options("width") > ttbar > options(ow) > options("width") > > So this is just the print function for data.frame objects doing its > unsung job. A very useful function for looking at things when they > don't seem to be what you think is str(), which concisely says what > the structure of an object is, so str(ttbar) should tell you that it > is a data frame of 10 variables and 2 observations.Thanks to Roger for this clarification. I took the splitting of the variables to be a consequence of the delimiter and not just a benign consequence of the printed output (at least I presume this is the proper interpretation of Jan's problem.) The tab character is of course included in "whitespace"....using "\t" explicitly would be helpful if there is embedded whitespace (other than a tab) within a field. Marc <Off to get another cup of coffee....>