| import_Statechanges {LightLogR} | R Documentation |
Import data that contain Datetimes of Statechanges
Description
Auxiliary data greatly enhances data analysis. This function allows the
import of files that contain Statechanges, i.e., specific time points of
when a State (like sleep or wake) starts.
Usage
import_Statechanges(
filename,
path = NULL,
sep = ",",
dec = ".",
structure = c("wide", "long"),
Datetime.format = "ymdHMS",
tz = "UTC",
State.colnames,
State.encoding = State.colnames,
Datetime.column = Datetime,
Id.colname,
State.newname = State,
Id.newname = Id,
keep.all = FALSE,
silent = FALSE
)
Arguments
filename |
Filename(s) for the Dataset. Can also contain the filepath,
but |
path |
Optional path for the dataset(s). |
sep |
String that separates columns in the import file. Defaults to
|
dec |
String that indicates a decimal separator in the import file.
Defaults to |
structure |
String that specifies whether the import file is in the
|
Datetime.format |
String that specifies the format of the |
tz |
Timezone of the data. |
State.colnames |
Column name or vector of column names (the latter only
in the
|
State.encoding |
In the |
Datetime.column |
Symbol of the
|
Id.colname |
Symbol of the column that contains the |
State.newname |
Symbol of the column that will contain the |
Id.newname |
Column name used for renaming the |
keep.all |
Logical that specifies whether all columns should be
kept in the output. Defaults to |
silent |
Logical that specifies whether a summary of the
imported data should be shown. Defaults to |
Details
Data can be present in the long or wide format.
In the
wideformat, multipleDatetimecolumns indicate the state through the column name. These get pivoted to thelongformat and can be recoded through theState.encodingargument.In the
longformat, one column indicates theState, while the other gives theDatetime.
Value
a dataset with the ID, State, and Datetime columns. May contain
additional columns if keep.all is TRUE.
Examples
#get the example file from within the package
path <- system.file("extdata/",
package = "LightLogR")
file.sleep <- "205_sleepdiary_all_20230904.csv"
#import Data in the wide format (sleep/wake times)
import_Statechanges(file.sleep, path,
Datetime.format = "dmyHM",
State.colnames = c("sleep", "offset"),
State.encoding = c("sleep", "wake"),
Id.colname = record_id,
sep = ";",
dec = ",")
#import in the long format (Comments on sleep)
import_Statechanges(file.sleep, path,
Datetime.format = "dmyHM",
State.colnames = "comments",
Datetime.column = sleep,
Id.colname = record_id,
sep = ";",
dec = ",", structure = "long")