Re: [R] help working with date
values
steve_fried...@nps.gov wrote:
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
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
Here are a few ways:
xx - c(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)
# 1
library(zoo)
as.numeric(floor(as.yearmon(xx)))
[1] 1985 1985 1985 1985 1985 1985 1985 1985 1985 1985
#2
as.numeric(substr(xx, 1, 4))
4 matches
Mail list logo