I have daily weather data with columns for the day of the month, the month, the year, and the data. But I need to add another column for the day of the year. e.g 1 - 365 (or 366 for leap years).
I'm not much of a programmer at all, I am familiar with seq()
e.g. seq(1, 365)
But the above would terminate at 365. I need to sequentially increase the number while accounting for the year, so that the sequence starts over every year (and accounts for leap years). In this example, all weather data begin on Jan. 1st.
Any ideas/suggestion/pointers much appreciated.
Edit: Example data
example.data <- structure(list(V1 = 1:6, V2 = c(1L, 1L, 1L, 1L, 1L, 1L),
V3 = c(1950L, 1950L, 1950L, 1950L, 1950L, 1950L),
V4 = c(NA, NA, NA, NA, NA, NA),
V5 = c(0, 0, 0, 0, 0, 0)),
.Names = c("V1", "V2", "V3", "V4", "V5"), row.names = c(NA, 6L), class = "data.frame")`
dput(head(dat))
, wheredat
is the name of your data frame. – Aaron left Stack Overflow