Recode Sleep Stages in a Hypnogram
hypno_recode.RdRecodes sleep stage values in a specified column of a hypnogram dataframe, ensuring consistency
by mapping various input formats to standardized labels (N1, N2, N3, R, W, A).
Usage
hypno_recode(
df,
var,
N1 = NULL,
N2 = NULL,
N3 = NULL,
R = NULL,
W = NULL,
A = NULL,
unmatched_behavior = "warn"
)Arguments
- df
A dataframe containing the hypnogram data.
- var
A string specifying the column name in
dfthat contains sleep stages.- N1
A single value or vector of values to be recoded as
"N1"(default:NULL).- N2
A single value or vector of values to be recoded as
"N2"(default:NULL).- N3
A single value or vector of values to be recoded as
"N3"(default:NULL).- R
A single value or vector of values to be recoded as
"R"(REM sleep) (default:NULL).- W
A single value or vector of values to be recoded as
"W"(Wake) (default:NULL).- A
A single value or vector of values to be recoded as
"A"(Artifact) (default:NULL).- unmatched_behavior
How to handle unmatched values? Options:
"warn"(default, warns and keeps),"NA"(sets unmatched toNA),"unknown"(replaces with"UNKNOWN"),"artifact"(replaces with"A").
Examples
data <- data.frame(epoch = 1:5, stage = c(1, 2, 3, 5, 10))
hypno_recode(df = data, var = "stage", N1 = 1, N2 = 2, N3 = 3, R = 5, W = 10)
#> epoch stage
#> 1 1 N1
#> 2 2 N2
#> 3 3 N3
#> 4 4 R
#> 5 5 W