help working with date values
My data contains a variable "observation_date" and it contains values as: 1985-09-02 1985-09-15 1985-07-31 1985-09-02 I need to process data annually rather than daily, therefore I'm trying to 1) either extract the first 4 digits from this field and use them as a new variable "year" or 2) keep the variable as it is and process the analysis using the first 4 digits of the observation_date field. I'm not sure how to do either one of these approaches. I've looked in the R-archive help pages, date, strsplit and a few others
attach(gator) observation_date[1:10]
[1] 1985-09-02 1985-09-16 1985-07-31 1985-07-31 1985-09-02 1985-08-26 1985-07-31 1985-08-26 1985-09-02 1985-09-16
as.date(observation_date)
Error in as.date(observation_date) : Cannot coerce to date format
mode(observation_date)
"numeric"
y <- as.character(observation_date)
[1] "1985-09-02" "1985-09-16" "1985-07-31" "1985-07-31" "1985-09-02" "1985-08-26" "1985-07-31" "1985-08-26" "1985-09-02" "1985-09-16" < y.date <- as.date(y) [1] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> on and on and on ...
x <- strsplit(observation_date, "-")
Error in strsplit(observation_date, "-") : non-character argument All help is greatly appreciated. Thanks Steve 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