Skip to content
Prev 165038 / 398506 Next

Trouble pulling data from a messy ACII file...

On Wed, 17 Dec 2008, Titan8883 wrote:

            
Advice? OK. Here goes.

I would suggest you pull one of the data files into a character vector 
using readLines().
in the file that you want to extract. If it is guaranteed that 'nominal 
pulse width' ALWAYS shows up on the same line in every file, you can use 
the line numbers to figure out where to look for data elements. If not, 
you will probably want to get familiar with grep() and regular 
expressions, see ?regex and use RSiteSearch("regexpr") and the like to 
turn up the many useful discussions of them on this list.
take a good deal of fiddling to get them to digest your data.

If parts of your file can be read using read.csv() or scan() or something, 
you can use a textConnection() to pass some lines that readLines() has 
stored for you to read.csv().

Once you get so that one data file can be processed, rolling up your code 
as a function should not be too hard. Put the function in a loop using

 	res <- list()
 	for(ifile in your.file.list ) res[[ifile]] <- your.function( ifile)

or
 	res <-	sapply(your.file.list, your.function)
or

 	res <- lapply(your.file.list, your.function)

and you are ready to chomp away at your files.


HTH,

Chuck

I am trying to pull data from flat ASCII files, but they
Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901