[R] read a text file with variable number of spaces
Gerrit Eichner
Gerrit.Eichner at math.uni-giessen.de
Thu Mar 3 08:57:45 CET 2011
Hello, Gregory,
for your first data set see
?read.table
and for you second
?read.fwf
may help solving your problem.
Hth -- Gerrit
On Thu, 3 Mar 2011, Gregory Ryslik wrote:
> Hi,
>
>
> I seem to be having somewhat of an unusual data input problem with some
> of the data sets I'm working with and want to run a simulation on.
>
> in the first data set I'm looking at, I have a text file where the
> spacing between columns varies. I've attached a snippet. Is there a way
> to read this into R? Basically, I want to ignore all the spaces to make
> new columns. In a slightly different case, I have a long sequence of
> nucleotides (the letters are always either g,a,t,c). Is there a way to
> get each letter into it's own column so that I can then use it as a data
> set?
>
> I'm kind of loathe to program a java/C program to do this if I don't
> have to and was wondering if a way in R exists for this.
>
> Thanks!
> Greg
>
> Case1:
> ACE2_YEAST 0.42 0.37 0.59 0.20 0.50 0.00 0.52 0.29 NUC
> ACH1_YEAST 0.40 0.42 0.57 0.35 0.50 0.00 0.53 0.25 CYT
> ACON_YEAST 0.60 0.40 0.52 0.46 0.50 0.00 0.53 0.22 MIT
> ACR1_YEAST 0.66 0.55 0.45 0.19 0.50 0.00 0.46 0.22 MIT
> ACT_YEAST 0.46 0.44 0.52 0.11 0.50 0.00 0.50 0.22 CYT
> ACT2_YEAST 0.47 0.39 0.50 0.11 0.50 0.00 0.49 0.40 CYT
> ACT3_YEAST 0.58 0.47 0.54 0.11 0.50 0.00 0.51 0.26 NUC
> ACT5_YEAST 0.50 0.34 0.55 0.21 0.50 0.00 0.49 0.22 NUC
>
> Case2:
> gtacagtacgtacgtacgatcgatctagcatgcatgcatgcatgcta
> ______________________________________________
> 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