View source: R/import_States.R
import_Statechanges | R Documentation |
Datetimes
of Statechanges
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.
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
)
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 |
Data can be present in the long or wide format.
In the wide
format, multiple Datetime
columns indicate the state through the column name. These get pivoted to the long
format and can be recoded through the State.encoding
argument.
In the long
format, one column indicates the State
, while the other gives the Datetime
.
a dataset with the ID
, State
, and Datetime
columns. May contain
additional columns if keep.all
is TRUE
.
#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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.