On Sep 28, 2009, at 4:07 PM, steve_fried...@nps.gov wrote:


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.

They probably look that same on someone's spreadsheet but could have some invisible character of smart-quotes or some other formatting anomaly. What does str show you about the types of your variables? How about summary or Design::describe? Do they say htat the data.frames have tha same structure and lack of "string anomalies".


Are there any known issues with ts, what are the suggested solutions?


--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to