[R] error in seq.POSIXt?

Brandon Whitcher whitcher at cgd.ucar.edu
Fri May 31 23:27:23 CEST 2002


I am trying to extract only the winters (defined to be 01-Dec through
28-Feb) of daily data from 1948-2002.  There are 90 days in each winter
season.  I wrote the following code to gather the winter dates into a
single vector:

DJF <- NULL
for(year in 1949:1999) {
  temp.begin <- strptime(paste("01/12", year-1, sep="/"), "%d/%m/%Y")
  temp.end <- strptime(paste("28/02", year, sep="/"), "%d/%m/%Y")
  ## Gives wrong answer:
  temp.seq <- seq(temp.begin, temp.end, by="day")
  if(is.null(DJF))
    DJF <- temp.seq
  else
    DJF <- c(DJF, temp.seq)
  cat("Winter:", year, "\t", length(temp.seq), "\n")
}

with the following output:

Winter: 1949 	 90
Winter: 1950 	 90
Winter: 1951 	 90
Winter: 1952 	 90
Winter: 1953 	 90
Winter: 1954 	 90
Winter: 1955 	 90
Winter: 1956 	 90
Winter: 1957 	 90
Winter: 1958 	 90
Winter: 1959 	 90
Winter: 1960 	 90
Winter: 1961 	 90
Winter: 1962 	 90
Winter: 1963 	 90
Winter: 1964 	 90
Winter: 1965 	 90
Winter: 1966 	 90
Winter: 1967 	 90
Winter: 1968 	 90
Winter: 1969 	 90
Winter: 1970 	 90
Winter: 1971 	 90
Winter: 1972 	 90
Winter: 1973 	 90
Winter: 1974 	 89
Winter: 1975 	 89
Winter: 1976 	 90
Winter: 1977 	 90
Winter: 1978 	 90
Winter: 1979 	 90
Winter: 1980 	 90
Winter: 1981 	 90
Winter: 1982 	 90
Winter: 1983 	 90
Winter: 1984 	 90
Winter: 1985 	 90
Winter: 1986 	 90
Winter: 1987 	 90
Winter: 1988 	 90
Winter: 1989 	 90
Winter: 1990 	 90
Winter: 1991 	 90
Winter: 1992 	 90
Winter: 1993 	 90
Winter: 1994 	 90
Winter: 1995 	 90
Winter: 1996 	 90
Winter: 1997 	 90
Winter: 1998 	 90
Winter: 1999 	 90
Winter: 2000 	 90
Winter: 2001 	 90
Winter: 2002 	 90

There are two years, 1974 and 1975, that produce only 89 days per winter.
I could not figure out what the cause of this was, but a workaround is two
rewrite the call to seq.POSIXt as:

temp.seq <- seq(temp.begin, length.out=90, by="day")

I am unsure why one works and one does not.  Any ideas?

Brandon

----------------------------------------------------------------------------
  Geophysical Statistics Project
  National Center for Atmospheric Research          +1 303 497 1709  voice
  P.O. Box 3000, Boulder, CO  80307-3000            +1 303 497 1333  fax

  whitcher at ucar.edu                            www.cgd.ucar.edu/~whitcher/
----------------------------------------------------------------------------





-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list