Hello everyone I'm working with R 2.8.1 on a windows machine I have a question regarding time series analysis The first question is how does R expect the input file to be structured? I'm working with a *.txt file similar to the abbreviated one here: Date,stage 4/2/1953,7.56 4/3/1953,7.56 4/4/1953,7.54 4/5/1953,7.53 4/6/1953,7.5 4/7/1953,7.47 4/8/1953,7.44 4/9/1953,7.41 4/10/1953,7.37 4/11/1953,7.33 4/12/1953,7.3 4/13/1953,7.26 4/14/1953,7.28 4/15/1953,7.28 4/16/1953,7.23 4/17/1953,7.47 4/18/1953,7.59 4/19/1953,7.58 4/20/1953,7.57 4/21/1953,7.56 4/22/1953,7.55 4/23/1953,7.53 4/24/1953,7.51 4/25/1953,7.48 4/26/1953,7.46 4/27/1953,7.5 4/28/1953,7.56 The data record is substantially longer - 50 years worth of daily hydrologic water stage data (column 2). R seems to get confused by the format of this input not knowing what to do with the date field, and also deciding to treat everything as a level. I'm reading the data as follows: mystage <- read.table("C:\\Documents and Settings\\skfriedman\\Desktop\\R-scripts\\stage.txt", header = TRUE) looking at the data I get the following: mystage[1:4,] [1] 4/2/1953,7.56 4/3/1953,7.56 4/4/1953,7.54 4/5/1953,7.53 20195 Levels: 1/1/1954,8.72 1/1/1955,8.48 1/1/1956,7.94 1/1/1957,7.88 1/1/1958,8.5 ... 9/9/2007,8.84>What I'd like is a time series with a starting data of April 21, 1953. ending December 30, 2008. data are daily records, so the frequency should be 365 (?) not counting leap year nuisances. So the first question is how should I build the input file to correctly import it to a time series with an odd beginning date? The analysis I'm really trying to get to will involve calculating the mean monthly stage, the mean seasonal (aggregated over several months) stage, the annual maximum period with a continuous stage greater than 0. Thanks in advance I will summary solutions. Much appreciated Steve Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 Steve_Friedman at nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147
To seperate the columns, use the "sep" argument in read.table() mystage <- read.table("C:\\Documents and Settings\\skfriedman\\Desktop\\R-scripts\\stage.txt", header TRUE,sep=',') On Fri, Jan 30, 2009 at 4:17 PM, <Steve_Friedman at nps.gov> wrote:> > Hello everyone > > > I'm working with R 2.8.1 on a windows machine > > I have a question regarding time series analysis > > The first question is how does R expect the input file to be structured? > I'm working with a *.txt file similar to the abbreviated one here: > > Date,stage > 4/2/1953,7.56 > 4/3/1953,7.56 > 4/4/1953,7.54 > 4/5/1953,7.53 > 4/6/1953,7.5 > 4/7/1953,7.47 > 4/8/1953,7.44 > 4/9/1953,7.41 > 4/10/1953,7.37 > 4/11/1953,7.33 > 4/12/1953,7.3 > 4/13/1953,7.26 > 4/14/1953,7.28 > 4/15/1953,7.28 > 4/16/1953,7.23 > 4/17/1953,7.47 > 4/18/1953,7.59 > 4/19/1953,7.58 > 4/20/1953,7.57 > 4/21/1953,7.56 > 4/22/1953,7.55 > 4/23/1953,7.53 > 4/24/1953,7.51 > 4/25/1953,7.48 > 4/26/1953,7.46 > 4/27/1953,7.5 > 4/28/1953,7.56 > > The data record is substantially longer - 50 years worth of daily > hydrologic water stage data (column 2). > > R seems to get confused by the format of this input not knowing what to do > with the date field, and also deciding to treat everything as a level. > > I'm reading the data as follows: > > mystage <- read.table("C:\\Documents and > Settings\\skfriedman\\Desktop\\R-scripts\\stage.txt", header = TRUE) > > looking at the data I get the following: > > mystage[1:4,] > [1] 4/2/1953,7.56 4/3/1953,7.56 4/4/1953,7.54 4/5/1953,7.53 > 20195 Levels: 1/1/1954,8.72 1/1/1955,8.48 1/1/1956,7.94 1/1/1957,7.88 > 1/1/1958,8.5 ... 9/9/2007,8.84 >> > > What I'd like is a time series with a starting data of April 21, 1953. > ending December 30, 2008. data are daily records, so the frequency should > be 365 (?) not counting leap year nuisances. > > So the first question is how should I build the input file to correctly > import it to a time series with an odd beginning date? > > The analysis I'm really trying to get to will involve calculating the mean > monthly stage, the mean seasonal (aggregated over several months) stage, > the annual maximum period with a continuous stage greater than 0. > > Thanks in advance I will summary solutions. > > Much appreciated > > Steve > > Steve Friedman Ph. D. > Spatial Statistical Analyst > Everglades and Dry Tortugas National Park > 950 N Krome Ave (3rd Floor) > Homestead, Florida 33034 > > Steve_Friedman at nps.gov > Office (305) 224 - 4282 > Fax (305) 224 - 4147 > > ______________________________________________ > 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. >-- Mike Lawrence Graduate Student Department of Psychology Dalhousie University www.thatmike.com Looking to arrange a meeting? Check my public calendar: http://www.thatmike.com/mikes-public-calendar ~ Certainty is folly... I think. ~
Copy and paste this into an R session: Lines <- "Date,stage 4/2/1953,7.56 4/3/1953,7.56 4/4/1953,7.54 4/5/1953,7.53 4/6/1953,7.5 4/7/1953,7.47 4/8/1953,7.44 4/9/1953,7.41 4/10/1953,7.37 4/11/1953,7.33 4/12/1953,7.3 4/13/1953,7.26 4/14/1953,7.28 4/15/1953,7.28 4/16/1953,7.23 4/17/1953,7.47 4/18/1953,7.59 4/19/1953,7.58 4/20/1953,7.57 4/21/1953,7.56 4/22/1953,7.55 4/23/1953,7.53 4/24/1953,7.51 4/25/1953,7.48 4/26/1953,7.46 4/27/1953,7.5 4/28/1953,7.56" library(zoo) library(chron) # z <- read.zoo("myfile.csv", header = TRUE, sep = ",", FUN = as.chron) z <- read.zoo(textConnection(Lines), header = TRUE, sep = ",", FUN = as.chron) plot(z) On Fri, Jan 30, 2009 at 3:17 PM, <Steve_Friedman at nps.gov> wrote:> > Hello everyone > > > I'm working with R 2.8.1 on a windows machine > > I have a question regarding time series analysis > > The first question is how does R expect the input file to be structured? > I'm working with a *.txt file similar to the abbreviated one here: > > Date,stage > 4/2/1953,7.56 > 4/3/1953,7.56 > 4/4/1953,7.54 > 4/5/1953,7.53 > 4/6/1953,7.5 > 4/7/1953,7.47 > 4/8/1953,7.44 > 4/9/1953,7.41 > 4/10/1953,7.37 > 4/11/1953,7.33 > 4/12/1953,7.3 > 4/13/1953,7.26 > 4/14/1953,7.28 > 4/15/1953,7.28 > 4/16/1953,7.23 > 4/17/1953,7.47 > 4/18/1953,7.59 > 4/19/1953,7.58 > 4/20/1953,7.57 > 4/21/1953,7.56 > 4/22/1953,7.55 > 4/23/1953,7.53 > 4/24/1953,7.51 > 4/25/1953,7.48 > 4/26/1953,7.46 > 4/27/1953,7.5 > 4/28/1953,7.56 > > The data record is substantially longer - 50 years worth of daily > hydrologic water stage data (column 2). > > R seems to get confused by the format of this input not knowing what to do > with the date field, and also deciding to treat everything as a level. > > I'm reading the data as follows: > > mystage <- read.table("C:\\Documents and > Settings\\skfriedman\\Desktop\\R-scripts\\stage.txt", header = TRUE) > > looking at the data I get the following: > > mystage[1:4,] > [1] 4/2/1953,7.56 4/3/1953,7.56 4/4/1953,7.54 4/5/1953,7.53 > 20195 Levels: 1/1/1954,8.72 1/1/1955,8.48 1/1/1956,7.94 1/1/1957,7.88 > 1/1/1958,8.5 ... 9/9/2007,8.84 >> > > What I'd like is a time series with a starting data of April 21, 1953. > ending December 30, 2008. data are daily records, so the frequency should > be 365 (?) not counting leap year nuisances. > > So the first question is how should I build the input file to correctly > import it to a time series with an odd beginning date? > > The analysis I'm really trying to get to will involve calculating the mean > monthly stage, the mean seasonal (aggregated over several months) stage, > the annual maximum period with a continuous stage greater than 0. > > Thanks in advance I will summary solutions. > > Much appreciated > > Steve > > Steve Friedman Ph. D. > Spatial Statistical Analyst > Everglades and Dry Tortugas National Park > 950 N Krome Ave (3rd Floor) > Homestead, Florida 33034 > > Steve_Friedman at nps.gov > Office (305) 224 - 4282 > Fax (305) 224 - 4147 > > ______________________________________________ > 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. >