[R] Times series data file?

David Winsemius dwinsemius at comcast.net
Mon Jun 14 23:42:52 CEST 2010


On Jun 14, 2010, at 4:45 PM, Douglas M. Hultstrand wrote:

> Hello,
>
> I currently splitting a file into individual files (time series each  
> separated into one file), the file I read in skips the first four  
> lines and extracts the data columns I need.  I was wondering if  
> there is a way for R to automatically scan and separate the files  
> based on the head information?
>
> The header delineates the observation with a 254 space time space  
> day space month space year.
> 254      0     26      NOV    1995
>
> I would like to then use the program I have written to do the  
> analysis.  I have attached a small subset text file of data (two  
> observations).  Any thoughts would be very helpful.
>
> # Read in data file
> data <- read.table("file.txt", skip=4, header=F)
> temp <- data$V4
> elev <- data$V3

Yes:

 > ctxt <- textConnection("\n\n\n\n254      0     26      NOV    1995\n 
\n\n")
# simulating a file with four lines to be skipped and a fifth line to  
be read
 >> dat <- read.table(file=ctxt, skip=4, header=F, nrows=1)
 > str(dat)
'data.frame':	1 obs. of  5 variables:
  $ V1: int 254
  $ V2: int 0
  $ V3: int 26
  $ V4: Factor w/ 1 level "NOV": 1
  $ V5: int 1995

If you wanted the months to be character variables then use as.is=TRUE  
or stringsAsFactors=FALSE to control the default creation of factors.


>
> Thank you,
> Doug
>
> -- 
> ---------------------------------
> Douglas M. Hultstrand, MS
> Senior Hydrometeorologist
> Metstat, Inc. Windsor, Colorado
> voice: 720.771.5840
> email: dmhultst at metstat.com
> web: http://www.metstat.com
> ---------------------------------
>
>    254      0     26      NOV    1995
>      1  24232  72694  44.92N123.02W    61   2302
>      2    100   1960   2680    149  99999      4
>      3           SLE                99999     kt
>      9  10071     61    106     94    180     10
>      5  10037     89    110     82    183     12
>      4  10000    120    106     84    186     12
>      6   9780    304  99999  99999    205     19
>      6   9500    544     74     59    221     19
>    254     12     26      NOV    1995
>      1  24232  72694  44.92N123.02W    61   2302
>      2    100   1960   2680    149  99999      4
>      3           SLE                99999     kt
>      9  10071     61    106     94    180     10
>      5  10037     89    110     82    183     12
>      4  10000    120    106     84    186     12
>      6   9780    304  99999  99999    205     19
>      6   9500    544     74     59    221     19
> ______________________________________________
> R-help at 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list