Title: | Functions supporting data analysis with R at KWB |
---|---|
Description: | This package originally contained all the different helper functions developed and used at KWB. As it grew, functions were extracted into new packages that are dedicated to certain topics. The database access functions, for example, that were originally contained here, are now in the package kwb.db. Functions that help to create event information from time series data have been moved to kwb.event and date/time related functions are now in kwb.datetime. This package still contains some functions that are used in different scripts of different KWB projects. Currently, when loading this package, the packages kwb.datetime, kwb.db, kwb.event, kwb.plot and kwb.utils are automatically loaded. I plan to change this behaviour with the next release so that you need to load the other packages explicitly, i.e. with library(kwb.datetime), library(kwb.db), etc. |
Authors: | Hauke Sonnenberg [aut, cre] , Michael Rustler [ctb] , FAKIN [fnd], MIA-CSO [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
Maintainer: | Hauke Sonnenberg <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.0 |
Built: | 2024-10-26 02:54:47 UTC |
Source: | https://github.com/KWB-R/kwb.base |
Generates an artificial hydrograph
artificialHydrograph(step.s = 3600, from = "2015-01-01", to = "2015-01-10")
artificialHydrograph(step.s = 3600, from = "2015-01-01", to = "2015-01-10")
step.s |
time step in seconds |
from |
first day as character string in format "yyyy-mm-dd" |
to |
last day as character string in format "yyyy-mm-dd" |
data frame with columns DateTime and values
Check for Overlapping Time Sequences
checkForOverlappingTimeSequences( dataFrame, main = "Overlapping time sequences in hydraulic data" )
checkForOverlappingTimeSequences( dataFrame, main = "Overlapping time sequences in hydraulic data" )
dataFrame |
frame with timestamps in first column |
main |
plot title, passed to |
TRUE
if there are overlapping sequences, else FALSE
Convert Time Series Data Frame to xts Object
dataFrameToXts( dataFrame, timeColumn = names(dataFrame)[kwb.utils::posixColumnAtPosition(dataFrame)[1]] )
dataFrameToXts( dataFrame, timeColumn = names(dataFrame)[kwb.utils::posixColumnAtPosition(dataFrame)[1]] )
dataFrame |
data frame containing a timestamp column |
timeColumn |
name or number of time column. Default: first POSIXt-column in dataFrame |
xts object with timestamps taken from timestamp column. Non-numeric columns are removed.
Create Plot Demonstrating hsFillUp()
demo_hsFillUp()
demo_hsFillUp()
demo plot hsFillUp
Creates a plot demonstrating the effect of offset1 and offset2 in function hsGroupByInterval
demoGroupByInterval( df = hsExampleTSeries(60), step = kwb.datetime::minTimeStep(df[, 1]), to_pdf = TRUE )
demoGroupByInterval( df = hsExampleTSeries(60), step = kwb.datetime::minTimeStep(df[, 1]), to_pdf = TRUE )
df |
data frame containing data to be used for the demonstration |
step |
time step in seconds |
to_pdf |
if |
Based on the time series given in "tseries" a new time series is generated in which timestamps that are lacking in tseries are included. Optionally missing values are generated by interpolation between existing values.
fillup( tseries, tsField, step_s, forceStep, interpol, includeOrig, default = NA, dbg = FALSE )
fillup( tseries, tsField, step_s, forceStep, interpol, includeOrig, default = NA, dbg = FALSE )
tseries |
data frame representing a time-series of values |
tsField |
Name of timestamp column in tseries. Default: name of first available POSIXt-column |
step_s |
Time step in seconds that shall lie between consecutive timestamps. Non-existing timestamps are generated. |
forceStep |
If TRUE, only timestamps that are multiples of the time step given in step_s are put into the result data frame |
interpol |
if TRUE, the returned data frame will for each value column contain a corresponding column containing interpolated values |
includeOrig |
if TRUE and interpol = TRUE the original columns will remain in the output in addition to the columns containing all (original plus interpolated) values. |
default |
value to be used if there are not enough (at least to) non-NA values to be used for interpolation. Default: NA |
dbg |
If TRUE, debug messages are shown |
Returns a data.frame
First Timestamp in Data Frame
firstTimestamp(x)
firstTimestamp(x)
x |
data frame containing a date/time column |
Get Overlapping Time Sequences
getOverlappingTimeSequences(timestamps)
getOverlappingTimeSequences(timestamps)
timestamps |
vector of date and time objects, inheriting from
|
data frame with columns sequenceNo, tBeg, tEnd. In the attribute "sequenceNumber" the vector of sequenceNumbers, each of which corresponds to one timestamp is returned.
Get Sequence Number
getSequenceNumber(timestamps)
getSequenceNumber(timestamps)
timestamps |
vector of timestamps |
vector as long as timestamps containing numbers 1, 2, 3, ... indicating the belonging to a sequence of increasing timestamps. If the vector contains only ones, this means that timestamps is increasingly sorted.
Find Days of Daylight Saving
hsDaylightSaving(year.first = NULL, year.last = NULL)
hsDaylightSaving(year.first = NULL, year.last = NULL)
year.first |
first year of which daylight saving dates are to be calculated |
year.last |
last year of which daylight saving dates are to be calculated |
data frame with columns begST
(begin of summer time) and
endST
(end of summer time)
Plots the values of two database fields (= columns) against each other and prints the plot into a PDF file.
hsDbTablePlotXY(strDb, strTable, strX, strY, strPdfFile = NULL)
hsDbTablePlotXY(strDb, strTable, strX, strY, strPdfFile = NULL)
strDb |
full path to MS Access database file (*.mdb) |
strTable |
name of table in database |
strX |
name of table field containing the "x" values |
strY |
name of table field containing the "y" values |
strPdfFile |
full path to PDF file to be generated. If omitted, the plot is shown on the screen. |
If the output device is a pdf file the result of the dev.off() command is returned.
## Not run: ## Plot CSB vs. timestamp values from table "tbl_STA_CAL" in the ## example database into a window on the screen hsDbTablePlotXY(kwb.db::xmdb(), "tbl_Qua", "myDateTime", "CSB") ## Set paths to a test PDF file pdf_file <- file.path(tempdir(), "ex_hsDbTablePlotXY.pdf") ## Plot CSBf vs. timestamp values from the same table into a PDF file. hsDbTablePlotXY(kwb.db::xmdb(), "tbl_Qua", "myDateTime", "CSBf", pdf_file) ## Open PDF file in PDF viewer kwb.utils::hsShowPdf(pdf_file) ## End(Not run)
## Not run: ## Plot CSB vs. timestamp values from table "tbl_STA_CAL" in the ## example database into a window on the screen hsDbTablePlotXY(kwb.db::xmdb(), "tbl_Qua", "myDateTime", "CSB") ## Set paths to a test PDF file pdf_file <- file.path(tempdir(), "ex_hsDbTablePlotXY.pdf") ## Plot CSBf vs. timestamp values from the same table into a PDF file. hsDbTablePlotXY(kwb.db::xmdb(), "tbl_Qua", "myDateTime", "CSBf", pdf_file) ## Open PDF file in PDF viewer kwb.utils::hsShowPdf(pdf_file) ## End(Not run)
Delete Rows or Columns Containing only NA
hsDelNaRowsOrCols(df, rows = TRUE, drop = FALSE)
hsDelNaRowsOrCols(df, rows = TRUE, drop = FALSE)
df |
data frame |
rows |
if TRUE, rows that only contain NAs are deleted, else columns. |
drop |
if TRUE and only one row/column remains this row/column is returned in forms of a vector instead as a data frame. |
Example time series
hsExampleTSeries(step)
hsExampleTSeries(step)
step |
time step in seconds |
data frame with columns t (timestamp) and y (sinus values)
Based on the time series given in "tseries" a new time series is generated in which timestamps that are lacking in tseries are included. Optionally missing values are generated by interpolation between existing values.
hsFillUp( tseries, tsField = names(tseries)[kwb.utils::posixColumnAtPosition(tseries)[1]], step_s = 60, forceStep = TRUE, limits = NULL, interpol = TRUE, includeOrig = TRUE, default = NA, dbg = FALSE )
hsFillUp( tseries, tsField = names(tseries)[kwb.utils::posixColumnAtPosition(tseries)[1]], step_s = 60, forceStep = TRUE, limits = NULL, interpol = TRUE, includeOrig = TRUE, default = NA, dbg = FALSE )
tseries |
data frame representing a time-series of values |
tsField |
Name of timestamp column in tseries. Default: name of first available POSIXt-column |
step_s |
Time step in seconds that shall lie between consecutive timestamps. Non-existing timestamps are generated. |
forceStep |
If TRUE, only timestamps that are multiples of the time step given in step_s are put into the result data frame |
limits |
data frame or matrix with exactly two columns containing first and last timestamp of intervals for which timestamps are to be generated. |
interpol |
if TRUE, the returned data frame will for each value column contain a corresponding column containing interpolated values |
includeOrig |
if TRUE and interpol = TRUE the original columns will remain in the output in addition to the columns containing all (original plus interpolated) values. |
default |
value to be used if there are not enough (at least to) non-NA values to be used for interpolation. Default: NA |
dbg |
If TRUE, debug messages are shown |
Returns a data.frame
Filters a data.frame containing time series data for the time interval between minDate and maxDate.
hsFilterPeriod( tSeries, minDate, maxDate, tsField, maxIncluded = FALSE, dbg = FALSE )
hsFilterPeriod( tSeries, minDate, maxDate, tsField, maxIncluded = FALSE, dbg = FALSE )
tSeries |
data.frame containing time-series data. |
minDate |
lower boundary of time interval to be selected, as either of POSIXt-object, Date object or string in ISO format: yyyy-mm-dd |
maxDate |
upper boundary of time interval to be selected, as either of POSIXt-object, Date object or string in ISO format: yyyy-mm-dd |
tsField |
name of time stamp column in tseries. |
maxIncluded |
if TRUE, maxDate is included in the time interval to be filtered for, otherwise it is not included (see Details). |
dbg |
if |
minDate and maxDate must be given as character string in ISO format: “yyyy-mm-dd [HH:MM:SS]”, where the brackets indicate that time information is optional. The lower boundary is always included in the time interval to be selected, whereas the upper boundary is only included if maxIncluded is TRUE and otherwise excluded. With maxIncluded = FALSE it is easy to select whole months or whole years by setting maxDate to the first day of the next month/year.
Returns tSeries, reduced to rows representing a time within the selected time interval between minDate and maxDate
Filter for rows that have specified values in specified columns
hsFilterRowsWithValuesInColumns(dframe, columnValuePairs)
hsFilterRowsWithValuesInColumns(dframe, columnValuePairs)
dframe |
data frame |
columnValuePairs |
list of elements each of which defines a filter criterion in the form <column-name> = <value> |
data frame containing those rows of dframe that comply with all of the filter criteria defined in columnValuePairs
Groups data by values in two columns creating a matrix with as many rows as there are distinct values in field1 and as many columns as there are distinct values in field2. The matrix contains the sum of values in the specified value field that belong to the corresponding value combination of field1/field2
hsGroupBy2Fields( frmData, strValField, strField1, strField2, boolDesc1 = FALSE, boolDesc2 = FALSE )
hsGroupBy2Fields( frmData, strValField, strField1, strField2, boolDesc1 = FALSE, boolDesc2 = FALSE )
frmData |
data.frame containing data to be grouped. |
strValField |
name of value field (= column in frmData) |
strField1 |
name of first field to be grouped by |
strField2 |
name of second field to be grouped by |
boolDesc1 |
if TRUE, columns in result matrix will be ordered according to decreasing values of field1 |
boolDesc2 |
if TRUE, rows in result matrix will be ordered according to decreasing values of field2#' |
matrix with as many rows as there are distinct values in field1 and as many columns as there are distinct values in field2 of the input data.frame. The matrix contains the sum of values in the specified value field of the input data.frame that belong to the corresponding combination of values in field1/field2
Builds groups of rows belonging to the same time interval and aggregates the values within the group by using a given function (e.g. sum, mean, min, max)
hsGroupByInterval( data, interval, FUN, tsField = names(data)[1], offset1 = 0, offset2 = interval/2, limits = FALSE, ..., dbg = FALSE )
hsGroupByInterval( data, interval, FUN, tsField = names(data)[1], offset1 = 0, offset2 = interval/2, limits = FALSE, ..., dbg = FALSE )
data |
data frame containing a timestamp field and data fields to be aggregated over time. |
interval |
length of time interval in seconds |
FUN |
function used to aggregate the values within one and the same interval, e.g. sum, mean, min, max |
tsField |
name of timestamp column, default: name of first column |
offset1 |
number of seconds by which all timestamps are shifted before they are grouped into intervals. The grouping to intervals is done by dividing the timestamps (converted to number of seconds since 1970-01-01) by the interval length and taking the integer part of the division as interval number. Thus, with offset1 = 0 and an interval length of e.g. 60 seconds, the first interval is from 00:00:00 to 00:00:59, the second from 00:01:00 to 00:01:59 etc., whereas offset1 = 30 in this case would lead to intervals 00:00:30 to 00:01:29, 00:01:30 to 00:02:29 etc.. |
offset2 |
value given in seconds determining which of the timestamps in an interval represents the interval in the output. If 0, each time interval is represented by the smallest timestamp belonging to the interval. By default, offset2 is half the interval length, meaning that each time interval is represented by the timestamp in the middle of the interval. |
limits |
if TRUE, two additional columns will be added showing the minimum and maximum value of the interval |
... |
further arguments passed to aggregate, the internally called function |
dbg |
if TRUE, debug messages are shown |
## Get an example time-series with values every one minute step <- 60 df <- hsExampleTSeries(step) ## Calculate 5-min-means with ## offset1 = 0 (default), offset2 = interval/2 (default) df.agg1 <- hsGroupByInterval(df, interval = 5*step, mean, limits = TRUE) df.agg1 ## Shift the interval limits with ## offset1 = 2.5*60, offset2 = interval/2 (default) df.agg2 <- hsGroupByInterval(df, interval = 5*step, mean, limits = TRUE, offset1 = 2.5*step) df.agg2 ## Shift the timestamps representing the intervals with ## offset1 = 0, offset2 = 0 df.agg3 <- hsGroupByInterval(df, interval = 5*step, mean, limits = TRUE, offset1 = 0, offset2 = 0) df.agg3 ## Show a plot demonstrating the effect of offset1 and offset2 ## Not run: demoGroupByInterval(df) ## End(Not run) ## Handling NA values... ## Set y to NA at 2 random positions df[sample(nrow(df), 2), 2] <- NA df ## Let' have a look at df ## Count NA values per group hsGroupByInterval(df, interval = 300, function(x){sum(is.na(x))}) ## default behaviour: mean(values containing at least one NA) = NA hsGroupByInterval(df, interval = 300, mean) ## ignore NA values by passing na.rm = TRUE to the aggregate function hsGroupByInterval(df, interval = 300, mean, na.rm = TRUE)
## Get an example time-series with values every one minute step <- 60 df <- hsExampleTSeries(step) ## Calculate 5-min-means with ## offset1 = 0 (default), offset2 = interval/2 (default) df.agg1 <- hsGroupByInterval(df, interval = 5*step, mean, limits = TRUE) df.agg1 ## Shift the interval limits with ## offset1 = 2.5*60, offset2 = interval/2 (default) df.agg2 <- hsGroupByInterval(df, interval = 5*step, mean, limits = TRUE, offset1 = 2.5*step) df.agg2 ## Shift the timestamps representing the intervals with ## offset1 = 0, offset2 = 0 df.agg3 <- hsGroupByInterval(df, interval = 5*step, mean, limits = TRUE, offset1 = 0, offset2 = 0) df.agg3 ## Show a plot demonstrating the effect of offset1 and offset2 ## Not run: demoGroupByInterval(df) ## End(Not run) ## Handling NA values... ## Set y to NA at 2 random positions df[sample(nrow(df), 2), 2] <- NA df ## Let' have a look at df ## Count NA values per group hsGroupByInterval(df, interval = 300, function(x){sum(is.na(x))}) ## default behaviour: mean(values containing at least one NA) = NA hsGroupByInterval(df, interval = 300, mean) ## ignore NA values by passing na.rm = TRUE to the aggregate function hsGroupByInterval(df, interval = 300, mean, na.rm = TRUE)
conversion of text representing a number, but possibly starting with "<" or ">" to indicate that the number exceeds the detection limit of an analysis method, to a valid number
hsLabValToVal( x, country, detLimFactorBelow = 0.5, detLimFactorAbove = 2, factors = c(`<` = detLimFactorBelow, `<<` = detLimFactorBelow, `>` = detLimFactorAbove, `>>` = detLimFactorAbove), stopOnError = TRUE )
hsLabValToVal( x, country, detLimFactorBelow = 0.5, detLimFactorAbove = 2, factors = c(`<` = detLimFactorBelow, `<<` = detLimFactorBelow, `>` = detLimFactorAbove, `>>` = detLimFactorAbove), stopOnError = TRUE )
x |
(vector of) character(s) representing values, possibly starting with "<" or ">" to indicate detection limit exceedance |
country |
"en" if value is given in English format (decimal point ".", thousands separator ",") or "de" if value is given in German format (decimal point ",", thousands separator "."). |
detLimFactorBelow |
factor by which detection limit is multiplied in order to get a valid value when the value was below the detection limit. Default value: 0.5 |
detLimFactorAbove |
factor by which detection limit is multiplied in order to get a valid value when the value was above the detection limit. Default value: 2 |
factors |
named vector of conversion factors to be multiplied with the numeric values if the name of the factor matches the prefix (e.g. "<", "<<", ">", ">>") found in front of the value. Set to NULL if not factors are to be applied |
stopOnError |
if TRUE, the program stops on conversion errors, otherwise shows a warning |
data frame with columns outOfLimit being one of "" (value within detection limits), "<" (value below detection limit) or ">" (value above detection limit) and numericValue containing the value which, in case of detection limit exceedance, may be a substitute value. If there were conversion errors, the column numericValue containing the indices of the wrongly formatted values in its attribute "errorIndices".
Conversion of text representing a number, but possibly starting with "<" or ">" to indicate that the number exceeds the detection limit of an analysis method, to a valid number
hsLabValToVal_old( x, country, detLimFactorBelow = 0.5, detLimFactorAbove = 2, stopOnError = TRUE )
hsLabValToVal_old( x, country, detLimFactorBelow = 0.5, detLimFactorAbove = 2, stopOnError = TRUE )
x |
(vector of) character(s) representing values, possibly starting with "<" or ">" to indicate detection limit exceedance |
country |
"en" if value is given in English format (decimal point ".", thousands separator ",") or "de" if value is given in German format (decimal point ",", thousands separator "."). |
detLimFactorBelow |
factor by which detection limit is multiplied in order to get a valid value when the value was below the detection limit. Default value: 0.5 |
detLimFactorAbove |
factor by which detection limit is multiplied in order to get a valid value when the value was above the detection limit. Default value: 2 |
stopOnError |
if TRUE, the program stops on conversion errors, otherwise shows a warning |
data frame with columns outOfLimit being one of "" (value within detection limits), "<" (value below detection limit) or ">" (value above detection limit) and numericValue containing the value which, in case of detection limit exceedance, may be a substitute value. If there were conversion errors, the column numericValue containing the indices of the wrongly formatted values in its attribute "errorIndices".
Number of rows needed to plot <nPlots> in a grid with <plotCols> plots per row.
hsMfRows(nPlots, nPlotsPerRow)
hsMfRows(nPlots, nPlotsPerRow)
nPlots |
number of total plots |
nPlotsPerRow |
number of plots per row |
Number of rows needed to place all the plots.
Creates timestamps between first timestamp from and to with a distance of step.s seconds between the timestamps. If mdb is given, the timestamps are written to a database table in which the timestamp field is the primary key.
hsMkTimestamps(from, to, step.s = 60, mdb, tbl, dbg = FALSE)
hsMkTimestamps(from, to, step.s = 60, mdb, tbl, dbg = FALSE)
from |
first timestamp in ISO-Syntax: yyyy-mm-dd [HH:MM:SS] where the part in brackets is optional. |
to |
last timestamp in ISO-Syntax: yyyy-mm-dd [HH:MM:SS] where the part in brackets is optional. |
step.s |
time step between the timestamps in seconds. |
mdb |
Optional. Full path to MS Access database file (*.mdb). |
tbl |
Optional. Name of table to be created in mdb. If no name is given a name of the type tblfrom_to_to_step.s_s is created. If a table of given name exists, a non-existing name is generated first, so existing tables will not be overwritten. |
dbg |
if TRUE, debug messages are shown. |
Returns vecotor of timestamps if mdb is missing or nothing if timestamp table has been generated in database given in mdb.
## Not run: ## Write timestamps of January 2011 with five minutes step into example db. hsMkTimestamps("2011-01-01", "2011-02-01", 300, kwb.db::xmdb()) ## End(Not run) ## Output: # Timestamps have been written to table # 'tblTimestamps_2011_01_01_to_2011_02_01_300s' in # 'C:/Users/hsonne/Documents/R/win-library/2.14/ # kwb.base/extdata/RExKwbBase.mdb'. # Timestamp field has been set as primary key.
## Not run: ## Write timestamps of January 2011 with five minutes step into example db. hsMkTimestamps("2011-01-01", "2011-02-01", 300, kwb.db::xmdb()) ## End(Not run) ## Output: # Timestamps have been written to table # 'tblTimestamps_2011_01_01_to_2011_02_01_300s' in # 'C:/Users/hsonne/Documents/R/win-library/2.14/ # kwb.base/extdata/RExKwbBase.mdb'. # Timestamp field has been set as primary key.
Generates a nice vector of labels by suppressing labels at certain positions. Please use kwb.plot::niceLabels instead
hsNiceLabels(label, labelstep = NULL, labelpos = NULL, mindist = 1, offset = 0)
hsNiceLabels(label, labelstep = NULL, labelpos = NULL, mindist = 1, offset = 0)
label |
see |
labelstep |
see |
labelpos |
see |
mindist |
see |
offset |
see |
Returns the IDs of the first or all opened pdf device(s).
hsPdfDev(all = FALSE)
hsPdfDev(all = FALSE)
all |
if TRUE, the ids of all pdf devices are returned, if FALSE, only the id of the first pdf device |
ID of first (all == FALSE) or IDs of all opened pdf devices,
as e.g. returned by dev.list
Generic function for redirecting a plot-command to a specific device.
hsPlot(dev, plotFun = graphics::plot, args)
hsPlot(dev, plotFun = graphics::plot, args)
dev |
device id |
plotFun |
plot-function to be used, e.g. |
args |
list of arguments to be passed to the function given in plotFun |
This function returns whtat the plot function given in plotFun
returns
Conversion of time series in summer time to time series in winter time
hsST2WT(tstamps, dbg = FALSE)
hsST2WT(tstamps, dbg = FALSE)
tstamps |
timestamps in summer time |
dbg |
if |
time series, shifted to winter time (timezone is set to "UTC")
Waits for the specified number of seconds.
hsWait(secs = 1)
hsWait(secs = 1)
secs |
number of seconds to wait |
Interval Width to Seconds
intervalWidthToSeconds(intervalWidth)
intervalWidthToSeconds(intervalWidth)
intervalWidth |
character string starting with numeric characters 0-9 and ending with either of "d" (days), "h" (hours) or "m" (minutes) |
Last Timestamp in Data Frame
lastTimestamp(x)
lastTimestamp(x)
x |
data frame containing a date/time column |
Plot Sequence Events
plotSequenceEvents( timestamps, sequences, main = "Overlapping time sequences in hydraulic data", language = "de" )
plotSequenceEvents( timestamps, sequences, main = "Overlapping time sequences in hydraulic data", language = "de" )
timestamps |
vector of timestamps |
sequences |
data frame as returned by
|
main |
plot title |
language |
"de" (German) or something else (English) |
Select Time Interval
selectTimeInterval( x, t1 = NULL, t2 = NULL, width = "-7d", posixColumn = kwb.utils::posixColumnAtPosition(x), dbg = TRUE )
selectTimeInterval( x, t1 = NULL, t2 = NULL, width = "-7d", posixColumn = kwb.utils::posixColumnAtPosition(x), dbg = TRUE )
x |
data frame with at least one time column |
t1 |
first timestamp as text, in yyyy-mm-dd format |
t2 |
optional. last timestamp as text, in yyyy-mm-dd format |
width |
interval width as text containing number and unit (one of "d" - day, "h" - hour, "m" - minute). E.g. "7d" = 7 days, "20m" = 20 minutes. The number may be negative indicating "last <number> units". |
posixColumn |
name or number of column in |
dbg |
if |
Select Time Interval Days
selectTimeIntervalDays( dat, days = 7, firstDay = as.character(as.Date(lastDay) - days), lastDay = substr(utils::tail(dat$DateTime, 1), 1, 10), dbg = TRUE )
selectTimeIntervalDays( dat, days = 7, firstDay = as.character(as.Date(lastDay) - days), lastDay = substr(utils::tail(dat$DateTime, 1), 1, 10), dbg = TRUE )
dat |
data frame with column "DateTime" |
days |
number of "last" days to select |
firstDay |
first day as text, in "yyyy-mm-dd" format |
lastDay |
last day as text, in "yyyy-mm-dd" format |
dbg |
if |