Divide into Groups and Reassemble (Time*DataFrame objects and POSIXct*)

Share:

Description

‘split’ divides the data in the vector ‘x’ into the groups defined by ‘f’. The replacement forms replace values corresponding to such a division. Here are listed ‘split’ methods defined for Time objects defined in the timetools package POSIXst, POSIXcti, etc.). See sections below for complete list of methods.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  ## S4 method for signature 'ANY,POSIXctp'
split(x, f, drop = FALSE, ...)
  ## S4 method for signature 'ANY,POSIXcti'
split(x, f, drop = FALSE, ...)
  ## S4 method for signature 'ANY,POSIXst'
split(x, f, drop = FALSE, ...)

  ## S4 method for signature 'TimeIntervalDataFrame,TimeIntervalDataFrame'
split(x, f, ..., split.x=FALSE, keep.f=TRUE)
  ## S4 method for signature 'TimeIntervalDataFrame,POSIXcti'
split(x, f, ..., split.x=FALSE)
  ## S4 method for signature 'TimeIntervalDataFrame,POSIXctp'
split(x, f, ...,  split.x=FALSE)

Arguments

x

data frame containing values to be divided into groups. TimeIntervalDataFrame as data.frame.

f

Can be of different kind. Is used to defined the grouping. See details below.

drop

logical indicating if levels that do not occur should be dropped (if f is a factor or a list).

...

further potential arguments passed to methods.

split.x

logical indicating if data in x that are over several intervals or not completely included in one interval of f must be 'cut' to fit to new intervals (TRUE) or ignored (FALSE).

keep.f

logical indicating if f values must be kept on the resulting list.

Details

For each new split method defined in timetools a short description is given there.

Value

The value returned from ‘split’ is a list of vectors containing the values for the groups. The components of the list are named by the levels of f (after converting to a factor). The class of each element of the list is the one of the initial x structure.

Split over POSIX*t* objects

Since POSIXst, POSIXctp and POSIXcti objects are similar to vector it must be possible to split other type of objects against those ones.

split(x, 'POSIXctp', drop=FALSE, ...)

'POSIXctp' is first cast as character (using format) and then the split is done.

split(x, 'POSIXcti', drop=FALSE, ...)

'POSIXcti' is first cast as character (using format) and then the split is done. The ... argument is used to specify the format if needed.

split(x, 'POSIXst', drop=FALSE, ...)

'POSIXst' is first cast as numeric and then the split is done.

split('TimeIntervalDataFrame', 'TimeIntervalDataFrame', ..., split.x = FALSE, keep.f = TRUE)

Split a TimeIntervalDataFrame into another TimeIntervalDataFrame.

The method takes each time interval of the first TimeIntervalDataFrame (TitDF) and searches with which time intervals of the second it intersects.

Each time interval of the first TItDF can intersect with none, one or several time intervals of the second TItDF. The arguments 'split.x' is defined to tell the method what to do :

  • if the time interval in the first TItDF (ti1) doesn't match any in the second TItDF, nothing to do

  • if it (ti1) matches one in the second TItDF (ti2) and is included inside it, it (ti1) is entirely taken in the final result

  • if it (ti1) intersects one and only one (ti2) inside the second TItDF, (ti1) is truncated to be included inside (ti2) if 'split.x' is TRUE and (ti1) is removed if 'split.x' is FALSE

  • if it (ti1) is over several time intervals of the second TItDF (ti2.a, ti2.b, etc.) :

    • if 'split.x' is TRUE, (ti1) is truncated into each ti2.x to be included inside each one

    • if 'split.x' is FALSE, (ti1) is removed.

split('TimeIntervalDataFrame', 'POSIXctp', ..., split.x = FALSE)

Split a TimeIntervalDataFrame into a time period (of length 1). A TimeIntervalDataFrame is created (cf TimeIntervalDataFrame constructor) and the the above method is called.

split('TimeIntervalDataFrame', 'POSIXcti', ..., split.x = FALSE)

Split a TimeIntervalDataFrame into time intervals (POSIXcti). It is exactly the same as splitting a TimeIntervalDataFrame into another except that 'f' has not data.

So a TimeIntervalDataFrame is created according to 'f' and the the above method is called.

See Also

split, TimeIntervalDataFrame-class, POSIXcti, POSIXst-class, POSIXctp-class

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.