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
On Sep 28, 2009, at 4:07 PM, Steve_Friedman at 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
Hi there, I am having trouble getting the plotting of multiple time series to work. I have used RBloomberg to download data, which I then convert to a data frame. After I have calculated my new index values, I would like to plot the new index. My problem is that I can't get the plot feature to show the dates properly. The resultant data frame DATA has row.names in the first column, which contains the dates from the RBloomberg download. Could one of the R wizards please point me in the right direction? Thanks in advance Summary of my code: conn <- blpConnect(iface="COM", timeout=12000, show.days="week",na.action="previous.days", periodicity="daily") data <- blpGetData(conn, tickers, "PX_LAST", start = chron("01/01/00"), end = NULL,barsize = NULL, barfields = NULL, retval = NULL) blpDisconnect(conn) DATA <- data.frame(data) . . . A few calculations . . . Strategy <- as.ts(DATA[,5]) Index <- as.ts(DATA[,6]) ts.plot(Strategy,Index,col=c("tomato","black")) -- View this message in context: http://www.nabble.com/Help-with-time-series-tp25990385p25990385.html Sent from the R help mailing list archive at Nabble.com.