-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathrecodeLevelsDS.R
More file actions
29 lines (24 loc) · 862 Bytes
/
recodeLevelsDS.R
File metadata and controls
29 lines (24 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#'
#' @title Recodes the levels of a categorical variables
#' @description The functions uses the input factor and generates a new factor
#' with new levels.
#' @param x a factor vector
#' @param classes a character vector the levels of the newt factor vector
#' @return a factor vector with the new levels
#' @author Gaye, A.
#' @export
#'
recodeLevelsDS <- function (x=NULL, classes=NULL){
# Check Permissive Privacy Control Level.
dsBase::checkPermissivePrivacyControlLevel(c('permissive', 'banana', 'carrot'))
# check if the input vector is valid (i.e. meets DataSHIELD criteria)
check <- isValidDS(x)
if(check){
# generate the new variable with the specified levels
levels(x) <- classes
}else{
# generate the new variable with the specified levels but with missing values
x[1:length(x)] <- NA
}
return(x)
}