Yong Wang
2007-May-20 21:48 UTC
[R] Why a multi column, tab delimited file has only one column after reading in with read.table specification sep="\t"
Dear all: I have a tab delimited file as following AGE WEIGHT PROTEIN ........ 6 20 3 ........ 8 39 4 ........ I tried to read it as following: data <- read.table(file,sep="\t",header=T); but there is only column for the data after reading in,: dim(data); [1] 200 1 the column name is "AGE...WEIGHT...........PROTEIN...." Any quick suggestion will be appreciated. Best Regards
John Kane
2007-May-20 22:26 UTC
[R] Why a multi column, tab delimited file has only one column after reading in with read.table specification sep="\t"
Are you sure that there are tabs? try sep="" ?read.table seems to say that this should work Otherwise try read.delimited. --- Yong Wang <wangyong1 at gmail.com> wrote:> Dear all: > I have a tab delimited file as following > > AGE WEIGHT PROTEIN ........ > 6 20 3 ........ > 8 39 4 ........ > > I tried to read it as following: > > data <- read.table(file,sep="\t",header=T); > > but there is only column for the data after reading > in,: > > dim(data); > [1] 200 1 > > the column name is > "AGE...WEIGHT...........PROTEIN...." > > > Any quick suggestion will be appreciated. > > Best Regards > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, > reproducible code. >
Peter Dalgaard
2007-May-20 22:31 UTC
[R] Why a multi column, tab delimited file has only one column after reading in with read.table specification sep="\t"
Yong Wang wrote:> Dear all: > I have a tab delimited file as following > > AGE WEIGHT PROTEIN ........ > 6 20 3 ........ > 8 39 4 ........ > > I tried to read it as following: > > data <- read.table(file,sep="\t",header=T); > > but there is only column for the data after reading in,: > > dim(data); > [1] 200 1 > > the column name is "AGE...WEIGHT...........PROTEIN...." > > > Any quick suggestion will be appreciated. > >The most obvious guess is that your file is not really TAB delimited, but have columns separated by whitespace, i.e. a number of blanks. Some text editors or emailers will convert one into the other.
Charles C. Berry
2007-May-20 22:33 UTC
[R] Why a multi column, tab delimited file has only one column after reading in with read.table specification sep="\t"
On Sun, 20 May 2007, Yong Wang wrote:> Dear all: > I have a tab delimited file as followingProbably you do NOT have a tab delimited file after all.> > AGE WEIGHT PROTEIN ........ > 6 20 3 ........ > 8 39 4 ........ > > I tried to read it as following: > > data <- read.table(file,sep="\t",header=T); >What do table( count.fields( file ) ) and table( count.fields( file, sep='\t' ) ) tell you? If the former gives the right number of fields, then you have white space without tabs separating the data elements. If they both tell you that you have only one filed in each line, your lines quoted, perhaps. Otherwise, can you "provide commented, minimal, self-contained, reproducible code" as requested below to demonstrate this behavior??> but there is only column for the data after reading in,: > > dim(data); > [1] 200 1 > > the column name is "AGE...WEIGHT...........PROTEIN...." > > > Any quick suggestion will be appreciated. > > Best Regards > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0901