[R] Loading 'akward' data file

Liaw, Andy andy_liaw at merck.com
Wed Jun 16 14:31:27 CEST 2004


Generally you'd use file() to open the file, then use readLines(), say
inside a while() loop to read one `chunk' at a time.  However, your example
looks a bit strange.  The possibility of empty line makes it a bit more
complicated, by that last couple of lines seems to suggest that you could
have a line of data follow by another line of data without variable label.
If that's true, I don't know how you would parse the file...

Andy

> From: Iago Mosqueira
> 
> Hello,
> 
> I need to load a somehow diffilcult data file. It has lines with
> variable names followed by a variable number of rows and columns of
> data, separated from the next variable sometimes by a blank line,
> sometimes simply by the new variable name. For example:
> 
> var1
> 123.33
> var2
> 938
> 
> var3
> 1,1,1,1,1,1
> var4
> 1,2,3,4,5
> 1,2,3,4,5
> 
> What would be the best startegy for loading a file like this? I would
> like to have it staored as a list with the variable names used to name
> the slots. Any pointers?
> 
> Many thanks,
> 
> 
> Iago
> 
> 
>  
> --
> Iago Mosqueira
> 
> Unidad de Investigacin Marina
> Marine Research Division
> 
> AZTI Fundazioa
> 
> Txatxarramendi Ugartea z/g
> 48395 Sukarrieta, Bizkaia
> Spain
> 
> Tfno. +(34) 94 602 94 00
> Fax   +(34) 94 602 94 01
> 
> email imosqueira at suk.azti.es
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list