[R] read file problem

2006-11-03 Thread Luis Ridao Cruz
R-help,

I have the following file I want to import to R (some lines
removed)


Calibrated CTD data for station:00280001
Calibrated:23/8  2001, Salinity Unsmoothed,  Fluorescence Uncalibrated
Maximum observed depth:36 m   
QUAL has one digit for each of pressure, temp., sal. and fluor.   
QUAL=1:Uncal.,  QUAL=2:OK,  QUAL=6:Interp.,  QUAL=9:No data   
  
DEPTH  CTDPRS  CTDTMP  CTDSAL  RAWFLU NUMB. QUAL
MDBAR IPTS-68  PSS-78  OBS.
  *** *** *** ***
1 1.0   2999
2 2.0  5.9793 35.1629.10717 2221
3 3.0  5.9797 35.1631.10117 2221
4 4.0  5.9809 35.1631.11812 2221
5 5.1  5.9811 35.1629.11542 2221
6 6.1  5.9810 35.1631.11618 2221
7 7.1  5.9797 35.1631.11615 2221
8 8.1  5.9798 35.1630.10213 2221
9 9.1  5.9792 35.1629.11311 2221
...

.


If I use :

read.table(file, skip = 10)

it works fine but sometimes the missing data are not only
in line number 1 ( 1 1.0   2999)
but in lines 1,2,3,,, and therefore R fails to import the data file

How can I fix it?
I have tried with the arguments 
strip.white = TRUE
, fill = TRUE
, blank.lines.skip = TRUE

but still not get what I want


Thanks in advance

 version
   _   
platform   i386-pc-mingw32 
arch   i386
os mingw32 
system i386, mingw32   
status 
major  2   
minor  4.0 
year   2006
month  10  
day03  
svn rev39566   
language   R   
version.string R version 2.4.0 (2006-10-03)

__
R-help@stat.math.ethz.ch 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.


Re: [R] read file problem

2006-11-03 Thread john seers \(IFR\)




Hi

If the file is tab delimited you could try something like this:

 a-read.delim(file, skip = 9, header=F, na.strings=NA)


Are you sure you want to skip 10 lines? (Is there a blank line
somewhere?)



J


 
---
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Luis Ridao Cruz
Sent: 03 November 2006 14:03
To: r-help@stat.math.ethz.ch
Subject: [R] read file problem


R-help,

I have the following file I want to import to R (some lines
removed)


Calibrated CTD data for station:00280001
Calibrated:23/8  2001, Salinity Unsmoothed,  Fluorescence Uncalibrated
Maximum observed depth:36 m   
QUAL has one digit for each of pressure, temp., sal. and fluor.   
QUAL=1:Uncal.,  QUAL=2:OK,  QUAL=6:Interp.,  QUAL=9:No data   
  
DEPTH  CTDPRS  CTDTMP  CTDSAL  RAWFLU NUMB. QUAL
MDBAR IPTS-68  PSS-78  OBS.
  *** *** *** ***
1 1.0   2999
2 2.0  5.9793 35.1629.10717 2221
3 3.0  5.9797 35.1631.10117 2221
4 4.0  5.9809 35.1631.11812 2221
5 5.1  5.9811 35.1629.11542 2221
6 6.1  5.9810 35.1631.11618 2221
7 7.1  5.9797 35.1631.11615 2221
8 8.1  5.9798 35.1630.10213 2221
9 9.1  5.9792 35.1629.11311 2221
...

.


If I use :

read.table(file, skip = 10)

it works fine but sometimes the missing data are not only
in line number 1 ( 1 1.0   2999)
but in lines 1,2,3,,, and therefore R fails to import the data file

How can I fix it?
I have tried with the arguments 
strip.white = TRUE
, fill = TRUE
, blank.lines.skip = TRUE

but still not get what I want


Thanks in advance

 version
   _   
platform   i386-pc-mingw32 
arch   i386
os mingw32 
system i386, mingw32   
status 
major  2   
minor  4.0 
year   2006
month  10  
day03  
svn rev39566   
language   R   
version.string R version 2.4.0 (2006-10-03)

__
R-help@stat.math.ethz.ch 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.

__
R-help@stat.math.ethz.ch 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.


Re: [R] read file problem

2006-11-03 Thread ronggui

You should pay attention to the argument na.string.

na.strings: a character vector of strings which are to be interpreted
 as 'NA' values.  Blank fields are also considered to be
 missing values in logical, integer, numeric and complex
 fields.


On 11/3/06, Luis Ridao Cruz [EMAIL PROTECTED] wrote:

R-help,

I have the following file I want to import to R (some lines
removed)


Calibrated CTD data for station:00280001
Calibrated:23/8  2001, Salinity Unsmoothed,  Fluorescence Uncalibrated
Maximum observed depth:36 m
QUAL has one digit for each of pressure, temp., sal. and fluor.
QUAL=1:Uncal.,  QUAL=2:OK,  QUAL=6:Interp.,  QUAL=9:No data

DEPTH  CTDPRS  CTDTMP  CTDSAL  RAWFLU NUMB. QUAL
MDBAR IPTS-68  PSS-78  OBS.
  *** *** *** ***
1 1.0   2999
2 2.0  5.9793 35.1629.10717 2221
3 3.0  5.9797 35.1631.10117 2221
4 4.0  5.9809 35.1631.11812 2221
5 5.1  5.9811 35.1629.11542 2221
6 6.1  5.9810 35.1631.11618 2221
7 7.1  5.9797 35.1631.11615 2221
8 8.1  5.9798 35.1630.10213 2221
9 9.1  5.9792 35.1629.11311 2221
...

.


If I use :

read.table(file, skip = 10)

it works fine but sometimes the missing data are not only
in line number 1 ( 1 1.0   2999)
but in lines 1,2,3,,, and therefore R fails to import the data file

How can I fix it?
I have tried with the arguments
strip.white = TRUE
, fill = TRUE
, blank.lines.skip = TRUE

but still not get what I want


Thanks in advance

 version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  4.0
year   2006
month  10
day03
svn rev39566
language   R
version.string R version 2.4.0 (2006-10-03)

__
R-help@stat.math.ethz.ch 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.




--
Ronggui Huang
Department of Sociology
Fudan University, Shanghai, China
黄荣贵
复旦大学社会学系

__
R-help@stat.math.ethz.ch 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.


Re: [R] read file problem

2006-11-03 Thread Philipp Pagel
On Fri, Nov 03, 2006 at 02:02:35PM +, Luis Ridao Cruz wrote:

 DEPTH  CTDPRS  CTDTMP  CTDSAL  RAWFLU NUMB. QUAL
 MDBAR IPTS-68  PSS-78  OBS.
   *** *** *** ***
 1 1.0   2999
 2 2.0  5.9793 35.1629.10717 2221
 3 3.0  5.9797 35.1631.10117 2221
 4 4.0  5.9809 35.1631.11812 2221
 5 5.1  5.9811 35.1629.11542 2221
 6 6.1  5.9810 35.1631.11618 2221
 7 7.1  5.9797 35.1631.11615 2221
 8 8.1  5.9798 35.1630.10213 2221
 9 9.1  5.9792 35.1629.11311 2221

 read.table(file, skip = 10)

To me it looks like your data is in a fixed-width format. If that is the
case you should use read.fwf() instead of read.table().

cu
Philipp

-- 
Dr. Philipp PagelTel.  +49-8161-71 2131
Dept. of Genome Oriented Bioinformatics  Fax.  +49-8161-71 2186
Technical University of Munich
Science Center Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

__
R-help@stat.math.ethz.ch 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.


Re: [R] read file problem

2006-11-03 Thread Jeff Newmiller
Luis Ridao Cruz wrote:
 R-help,
 
 I have the following file I want to import to R (some lines
 removed)
 
 
 Calibrated CTD data for station:00280001
 Calibrated:23/8  2001, Salinity Unsmoothed,  Fluorescence Uncalibrated
 Maximum observed depth:36 m   
 QUAL has one digit for each of pressure, temp., sal. and fluor.   
 QUAL=1:Uncal.,  QUAL=2:OK,  QUAL=6:Interp.,  QUAL=9:No data   
   
 DEPTH  CTDPRS  CTDTMP  CTDSAL  RAWFLU NUMB. QUAL
 MDBAR IPTS-68  PSS-78  OBS.
   *** *** *** ***
 1 1.0   2999
 2 2.0  5.9793 35.1629.10717 2221
 3 3.0  5.9797 35.1631.10117 2221
 4 4.0  5.9809 35.1631.11812 2221
 5 5.1  5.9811 35.1629.11542 2221
 6 6.1  5.9810 35.1631.11618 2221
 7 7.1  5.9797 35.1631.11615 2221
 8 8.1  5.9798 35.1630.10213 2221
 9 9.1  5.9792 35.1629.11311 2221
 ...
 
 .
 
 
 If I use :
 
 read.table(file, skip = 10)
 
 it works fine but sometimes the missing data are not only
 in line number 1 ( 1 1.0   2999)
 but in lines 1,2,3,,, and therefore R fails to import the data file
 
 How can I fix it?
 I have tried with the arguments 
 strip.white = TRUE
 , fill = TRUE
 , blank.lines.skip = TRUE
 
 but still not get what I want

This looks like a job for read.fwf...

?read.fwf

-- 
---
Jeff NewmillerThe .   .  Go Live...
DCN:[EMAIL PROTECTED]Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
R-help@stat.math.ethz.ch 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.