خرید بک لینک

Vote count: 0

This is embarrassing: I admit several pieces of code of mine have a similar structure to this:

enter image description here

Arghhhh! Do real programmers cringe when they see something like this?

The figure should be self-explanatory: I need a variable called Season that retus an ID "(year-1)_(year)" based on the WEATHERDATE column.

So, any row with dates from '1998-06-15' to '1999-06-14' should retu "1998-1999" under the Season ID Column.

The WEATHERDATE column simply runs from 1998-01-01 to TODAY.

I bet there's a one/two liner solution to this. I've tried the zoo package but no success.

Any R wizard to point me to the obvious solution I'm missing here?

***REPRODUCIBLE EXAMPLE:

WEATHERDATE <- seq(as.Date("1998-01-01"), len=99999, by=1)
VARIABLE    <- orm(n = length(WEATHERDATE))
data_mex    <- data.frame(WEATHERDATE, VARIABLE)
## how to create SEASON based on dates??
# I would then the code block from above here, something like:
data_mex <- within(data_mex, Season[DATEWEATHER >= ymd(StartOfSeason)+365*0   & DATEWEATHER < ymd(StartOfSeason)+365*1 ] <- "1998-1999") 

Of course a solution where I don't have to come back and touch the code every year would be ideal :)

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 18 ارديبهشت 1395 ساعت: 6:59

صفحه بندی