[R] Help with time series
Steve_Friedman at nps.gov
Steve_Friedman at nps.gov
Mon Sep 28 22:07:50 CEST 2009
Hello
I'm working with a bunch of time series data. The data are downloaded from
a server and stored as ascii files prior to reading them into R.
After reading the data sets read into R with no problem and I can us the ts
function to coerce them to time series, sometimes this works and sometimes
it fails.
For example.
P38_SubB <-
read.table("A:\\Data\\Output\\Sparrow\\Hydro_Data\\P38_Annual.txt",
header=TRUE, skip=1, sep=",", stringsAsFactors=FALSE)
P38_SubB$GS <- rep(0.85, dim(P38_SubB)[1]) # GS is the
ground surface elevation, which is not included in the initial file.
P38_SubB$Depth <- as.numeric(P38_SubB$P38_stage) -
as.numeric(P38_SubB$GS) # now I subtract the ground surface to calculate
water depth
P38_SubB.ts <- ts(data=P38_SubB, frequency = (1), start=c(1981, 1),
end=c(2009,1)) # Here I convert to a time series
plot(P38_SubB.ts,ylab="Mean Annual Water Depth", xlab="Year",
main="CSSP Subpopulation B \n Water Depth P38")
These lines work.
But these do not:
R3110_SubC <-
read.table("A:\\Data\\Output\\Sparrow\\Hydro_Data\\R3110_Annual.txt",
header=TRUE, skip=1, sep=",", stringsAsFactors=FALSE)
R3110_SubC$GS <- rep(5.10, dim(R3110_SubC)[1])
R3110_SubC$Depth <- as.numeric(R3110_SubC$R3110_stage) -
as.numeric(R3110_SubC$GS)
R3110_SubC.ts <- ts(data=R3110_SubC, frequency = (1), start=c(1984, 1),
end=c(2009, 1))
Warning message:
NAs introduced by coercion
I am asured that the input data are the same in each input file, yet some
coerce correctly while others result in the error which prevents plotting.
Are there any known issues with ts, what are the suggested solutions?
Thanks
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
More information about the R-help
mailing list