View source: R/Data_handling.R
strptime_eddy | R Documentation |
Converts character vector to class "POSIXct"
using
strptime
and validates the result. The input has to represent a
regular date-time sequence with given time interval. Additional attributes
varnames
and units
are assigned to returned vector with fixed
strings "timestamp"
and "-"
, respectively.
strptime_eddy(
x,
format = "%Y-%m-%d %H:%M",
interval = 1800L,
shift.by = NULL,
allow_gaps = FALSE,
tz = "GMT",
...
)
x |
A character vector containing date-time information to be converted
to class |
format |
A character string. The default |
interval |
A numeric value specifying the time interval (in seconds) of the input date-time vector. |
shift.by |
An integer value specifying the time shift (in seconds) to be applied to the date-time information. |
allow_gaps |
A logical value. If |
tz |
A time zone (see |
... |
Further arguments to be passed from or to other methods. |
Eddy covariance related measurements are usually stored with a timestamp
representing the end of the averaging period (typically 1800 s) in standard
time. This can however cause difficulties during data aggregation or
plotting. Therefore it is recommended to shift the date-time information
using shift.by
to represent the center of averaging period prior to
any computations. It is also recommended to change the date-time information
to its original state before saving to a file (see Examples section).
Any unsuccessful attempt to convert date-time information is considered to be
unexpected behavior and returns an error message instead of NA
value.
In case that multiple formats are present in the timestamp, it has to be
corrected prior using strptime_eddy
. It is expected that time series
are continuous even if no valid measurements are available for given time
interval. Therefore interval
value is checked against the lagged
differences (diff
) applied to the converted date-time vector
and returns an error message if mismatch is found. If allow_gaps =
TRUE
, date-time information does not have to be regular but time differences
must be multiples of interval
.
The storage mode of returned POSIXct vector is forced to be integer instead
of double. This simplifies application of round_df
but could
lead to unexpected behavior if the date-time information is expected to
resolve fractional seconds. Similarly as.integer
is applied to
shift.by
before it is added to the POSIXct vector to assure integer
storage mode of returned vector.
strptime
provides the details about conversions
between date-time character representation and "POSIXct"
or
"POSIXlt"
classes. It also includes information about format
conversion specification.
DateTimeClasses
further inform about the date-time classes.
See locales
to query or set a locale.
xx <- c("01.01.2014 00:30:00", "01.01.2014 01:00:00",
"01.01.2014 01:30:00", "01.01.2014 02:00:00")
varnames(xx) <- "timestamp"
units(xx) <- "-"
str(xx)
(yy <- strptime_eddy(xx, "%d.%m.%Y %H:%M", shift.by = -900L))
attributes(yy)
typeof(yy)
## Convert to original format
format(yy + 900, format = "%d.%m.%Y %H:%M", tz = "GMT")
zz <- xx[-3]
strptime_eddy(zz, "%d.%m.%Y %H:%M", allow_gaps = TRUE)
## Not run:
## This is not a regular date-time sequence
strptime_eddy(zz, "%d.%m.%Y %H:%M") # error returned
## interval argument provided incorrectly
strptime_eddy(xx, "%d.%m.%Y %H:%M", interval = 3600L)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.