hello, assume you have a txt-file (sep="\t" or "") looking as follows that you want to read into a variable: 1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 the result should look like this (e.g., in a data.frame): 1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 is there any way to do so? thanks in advance, jan
reading "special" text files
3 messages · Jan M. Wiener, Uwe Ligges, Brian Ripley
Jan Wiener wrote:
hello, assume you have a txt-file (sep="\t" or "") looking as follows that you want to read into a variable: 1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 the result should look like this (e.g., in a data.frame): 1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 is there any way to do so?
Yes, with e.g. sep="\t" and sep=" " the number of separators is taken into account. No, with sep="" the separator is *any* white space. Uwe Ligges
thanks in advance, 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
On Wed, 24 Aug 2005, Jan Wiener wrote:
hello, assume you have a txt-file (sep="\t" or "") looking as follows that you want to read into a variable:
Into a variable or a data frame?
1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 the result should look like this (e.g., in a data.frame):
With no column names? Not possible.
1 1 2 3 2 1 2 3 4 3 1 5 6 7 8 is there any way to do so?
I think we need to know what the structure here is. At a guess, the separator is multiple tabs as in the example. In that case
read.table("foo", header=FALSE, fill = TRUE)
V1 V2 V3 V4 V5 V6 1 1 1 2 3 NA NA 2 2 1 2 3 4 NA 3 3 1 5 6 7 8 or
read.table("foo", header=FALSE, fill = TRUE, row.names=1)
V2 V3 V4 V5 V6 1 1 2 3 NA NA 2 1 2 3 4 NA 3 1 5 6 7 8 does in essence what you want.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595