[R] How to scan concatenated(ish) vectors from a file?

David Pearson david.pearson at mail.nerc-essc.ac.uk
Fri Dec 6 18:06:11 CET 2002


Hi,

I have a text file containing lists of numbers with the
following structure:

a1,1   a1,2   a1,3   a1,4   a1,5 ...  a1,10
hm1,1  hm1,2  hm1,3  hm1,4  hm1,5 ... hm1,10
vm1,1  vm1,2  vm1,3  vm1,4  vm1,5 ... vm1,10
hx1,1  hx1,2  hx1,3  hx1,4  hx1,5 ... hx1,10
vx1,1  vx1,2  vx1,3  vx1,4  vx1,5 ... vx1,10
a2,1   a2,2   a2,3   a2,4   a2,5 ...  a2,10
hm2,1  hm2,2  hm2,3  hm2,4  hm2,5 ... hm2,10
vm2,1  vm2,2  vm2,3  vm2,4  vm2,5 ... vm2,10
hx2,1  hx2,2  hx2,3  hx2,4  hx2,5 ... hx2,10
vx2,1  vx2,2  vx2,3  vx2,4  vx2,5 ... vx2,10
a3,1   a3,2   a3,3   a3,4   a3,5 ...  a3,10
hm3,1  hm3,2  hm3,3  hm3,4  hm3,5 ... hm3,10
vm3,1  vm3,2  vm3,3  vm3,4  vm3,5 ... vm3,10
hx3,1  hx3,2  hx3,3  hx3,4  hx3,5 ... hx3,10
vx3,1  vx3,2  vx3,3  vx3,4  vx3,5 ... vx3,10

 ....... etc. .........

[I have pasted in a sample at the bottom of this mail]


That is, a 10-vector called a, then another called hm,
then one called vm, then one called hx, then one
called vx. 

Then there is another set of these five vectors, with
different values to the first, then a third set, and so
on.

I need to read these data into R, so that the
a-vectors form a matrix, the hm-vectors form a
matrix, and so on for vm, hx and vx.

It's as if the file contains five matrices that are
shuffled together in an ordered way, or interleaved,
and I want to unshuffle them.

I would be grateful for any advice on how to do this.


Regards
David Pearson,
University of Reading.



P.S. Example of first two repetitions:

     5.7746240000000   10.1944840000000    15.162860000000    19.972452000000
     24.969696000000    29.912084000000    34.990160000000    39.404248000000
     44.112800000000    51.705376000000
     221.05366300000    220.19684700000    218.72863700000    220.01943900000
     219.39893400000    218.72014800000    216.14767600000    215.09151600000
     214.89631500000    212.08561000000
     225.58556100000    223.46567500000    223.10528700000    223.30770900000
     221.60718200000    220.22865200000    217.55770500000    217.62152000000
     214.41164200000    209.87299100000
    -37.552579604438   -37.503499426212   -37.415562374465   -37.297161479559
    -37.139615098163   -36.950400331994   -36.724961035885   -36.509462976145
    -36.271029656279   -35.924838154422
    -37.618462088024   -37.708809366317   -37.869534364650   -38.083765603156
    -38.365379855039   -38.699298090554   -39.092923514193   -39.467900666263
    -39.887743069578   -40.551769666575
     5.1221840000000   10.1482920000000    15.315864000000    20.059060000000
     24.911956000000    29.834140000000    34.926648000000    40.027820000000
     44.981760000000    50.039628000000
     217.77643200000    218.39942900000    217.25389100000    218.11937400000
     218.47274000000    217.84758300000    216.54347200000    216.35888900000
     213.71289700000    212.37202300000
     220.74927700000    222.57766100000    222.07754500000    220.31385300000
     218.94588500000    219.35492500000    217.76563000000    215.84143400000
     214.52370500000    207.70436600000
    -48.400213454151   -48.371561781272   -48.320829545540   -48.253127540243
    -48.159889727331   -48.036491839658   -47.872856930063   -47.666010941283
    -47.418517030988   -47.116296503712
    -48.423571606915   -48.463583233282   -48.531684767151   -48.617406380304
    -48.726522122527   -48.856438207434   -49.005897285660   -49.161753650923
    -49.304896404495   -49.420843878184




More information about the R-help mailing list