Chattopadhyay, Somsubhra
2016-Mar-17 15:22 UTC
[R] Error in if (x[j, g] == x[i, g]) { : missing value where TRUE/FALSE needed
I am using the "hydroTSM" package and "trend" package to convert my daily time series into monthly and then analyze the seasonal trend. My code is y <-read.csv("P-GHCNDUSW00093820.csv",as.is=TRUE) y$DATE <- as.Date(as.character(y$DATE),format="%Y%m%d") x <- xts(y$PRCP,y$DATE) p <- daily2monthly(x, FUN=sum, na.rm = T) r <- as.ts(p) SeasonalMannKendall(r) The last line returns an error like Error in if (x[j, g] == x[i, g]) { : missing value where TRUE/FALSE needed I suspect that the error is because of the format of the time series object which may not be correct as in the attached image. It is making the monthly sums correct however I don't know why there are so many NA values. Each year should have only 12 values for the 12 months. Any ideas how to fix this error? -- *Somsubhra Chattopadhyay* Graduate Research Assistant Biosystems and Agricultural Engineering Department University of Kentucky, Lexington, KY 40546 Email: schattop14 at uky.edu Cell: 9198026951
David Winsemius
2016-Mar-17 20:53 UTC
[R] Error in if (x[j, g] == x[i, g]) { : missing value where TRUE/FALSE needed
> On Mar 17, 2016, at 8:22 AM, Chattopadhyay, Somsubhra <sch298 at g.uky.edu> wrote: > > I am using the "hydroTSM" package and "trend" package to convert my daily > time series into monthly and then analyze the seasonal trend. My code is > > y <-read.csv("P-GHCNDUSW00093820.csv",as.is=TRUE) > y$DATE <- as.Date(as.character(y$DATE),format="%Y%m%d") > x <- xts(y$PRCP,y$DATE) > p <- daily2monthly(x, FUN=sum, na.rm = T) > r <- as.ts(p) > SeasonalMannKendall(r) > > The last line returns an error like > Error in if (x[j, g] == x[i, g]) { : > missing value where TRUE/FALSE neededAfter each line of code you should be examining the results of `str` applied to the results to see if you are actually succeeding. And given the error message you might consider looking at: sum( is.na( y$DATE))> > I suspect that the error is because of the format of the time series object > which may not be correct as in the attached image.No image attached. Read the info page and the posting guide again.> It is making the monthly > sums correct however I don't know why there are so many NA values. Each > year should have only 12 values for the 12 months. > > Any ideas how to fix this error? > > > -- > *Somsubhra Chattopadhyay*-- David Winsemius Alameda, CA, USA