Closed SarinaAtkinson-NOAA closed 1 year ago
Reorder all of the mutates to create start date and end date to have smarter, more understandable code. Create a check to summarize the changes and overwriting of dates so we know what changes were made.
Reg 858 example we can test.
@AdyanRios-NOAA will tackle the start and end day of the week add/subtract issue
I found a forcats function fct_shift() that I thought would do the trick, but it more related to reordering for visuals. I could not find how to shift a factor by one. So I wrote code to do it. It is not very slick, but it works. I am going to put it into a branch to see what we think.
Create an ordered factor x <- factor(c("Mon", "Tue", "Wed"), levels = c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), ordered = TRUE)
x [1] Mon Tue Wed Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
Convert to numeric: y = as.numeric(x)
y [1] 2 3 4
Add one to everyone: z = y+1
z [1] 3 4 5
Redefine ordered factor (one level lower) i = z i[1] = i[1]-1
i [1] 2 4 5
Return to Factor
j = factor(i,
levels = c("1", "2", "3", "4", "5", "6", "7"),
ordered = TRUE)
j [1] 2 4 5 Levels: 1 < 2 < 3 < 4 < 5 < 6 < 7
Return to days of the week: k=j levels(k) = c("Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri")
k [1] Sun Tue Wed Levels: Sat < Sun < Mon < Tue < Wed < Thu < Fri
@SarinaAtkinson-NOAA
If you get a chance to review my latest commit and to practice branch merges ahead of Friday please give it a shot! The changes should make sense with the notes in the code.
recode_factor()ended up being a somewhat ok solution! A bit cleaner than what I had suggested in the comment above.
@AdyanRios-NOAA looks good! I only made one small change (see commit above). The change was only to retain original fields rather than recoding to numeric.
Discussed in https://github.com/SarinaAtkinson-NOAA/SEFSC-ODM-Management-History/discussions/8