try this: > input <- readLines(textConnection("header line + Ray1 header + gate1 1,2,3,4,5,6,7 + gate2 5,6,7,8,9,0 + Ray2 header + gate1 5,4,3,2,1 + gate2 8,7,6,5,4,34")) > closeAllConnections() > # delete first header line > input <- input[-1] > > # read the data one line at a time, parsing the data > result <- list() > for (line in input){ + # strip leading blanks + line <- sub("^ *", "", line) + x <- strsplit(line, ' ')[[1]] + if (x[2] == 'header'){ + key <- x[1] # save 'Rayn' as key to data + next + } + result[[key]][x[1]] <- list(as.numeric(strsplit(x[2], ',')[[1]])) + } > > result $Ray1 $Ray1$gate1 [1] 1 2 3 4 5 6 7
$Ray1$gate2 [1] 5 6 7 8 9 0 $Ray2 $Ray2$gate1 [1] 5 4 3 2 1 $Ray2$gate2 [1] 8 7 6 5 4 34 On Thu, Nov 12, 2009 at 1:02 AM, Justin Peter <j.pe...@bom.gov.au> wrote: > Dear r-help, > > I have a radar data file in the following format: > > nrays > for (1 to n_rays) > { some_data_info > for (1 to n_gates) > { some_data_info} > } > > N_rays=360 and n_gates=950 > > The data looks something like: > > Header line1 > Ray1 header > gate1 var1, var2,.....,varN > ... > gate950 var1, var2,.....,varN > Ray2 header > gate1 var1, var2,.....,varN > ... > gate950 var1, var2,.....,varN > ... > ... > ... > Ray360 header > gate1 var1, var2,.....,varN > ... > gate950 var1, var2,.....,varN > > I am having trouble reading this data. Are there any suggestions on how to > read the data file one block (corresponding to one ray) at a time? > > Any help appreciated. > > Regards, > Justin > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Dr. Justin R. Peter > Research Scientist > Queensland Climate Change Centre of Excellence > based at > Centre for Australian Weather and Climate Research (CAWCR), > A partnership between the Australian Bureau of Meteorology and CSIRO > > e: j.pe...@bom.gov.au<mailto:j.pe...@bom.gov.au> > p: +61 (0) 3 9669 4838 > f: +61 (0) 3 9669 4660 > s: Level 9 > Bureau of Meteorology Building > 700 Collins Street > Docklands > VIC 3008 > Australia > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@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.