Skip to content

Commit

Permalink
Remove elements that occur before the first bin when splitting by bins
Browse files Browse the repository at this point in the history
This change is in-line with the current treatment of the elements that
occur after the last bin.

Further, this fixes a minor "bug" where bin indecees are used to
determine bin labels by indexing into a list of labels. Elements before
the first bin received bin index 0, however, R is 1-indexed. Note: This
"bug" did not cause problems because the bin with the incorrect label
will be ignored later anyways.

Works towards se-sic#267.

Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler authored and Leo-Send committed Nov 13, 2024
1 parent 0594772 commit ac9abe7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions util-split.R
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,9 @@ split.data.by.time.or.bins = function(project.data, splitting.length, bins, spli
findInterval(df[["date"]], bins.date, all.inside = FALSE)
## split data according to df.bins
df.split = split(df, df.bins)
## remove events that occur before the first bin.
## these events are put in a bin with the name "0" by 'findInterval'
df.split = df.split[names(df.split) != "0"]
## add proper labels/names
names(df.split) = sapply(as.integer(names(df.split)), function(bin) bins[bin])
return(df.split)
Expand Down

0 comments on commit ac9abe7

Please sign in to comment.