Skip to content

Commit f9043c9

Browse files
committed
Added option to choose factor or integer as final data type on integer_encoder() function
1 parent dffd08d commit f9043c9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: encoder
22
Title: Data Encoding Methods for Categorical Features
3-
Version: 2.0.0
3+
Version: 2.1.0
44
Authors@R: c(
55
person(given = "Alfredo",
66
family = "Hernández",

R/integer_encoder.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
#'
33
#' @param data Input data frame
44
#' @param feature Unquoted form of the feature/column to encode
5+
#' @param as_factor Whether the factors should be converted to factors or pure integer
56
#'
67
#' @return
78
#' @export
89
#'
910
#' @examples
1011
#' set.seed(11)
1112
#' integer_encoder(iris[sample(1:150, 10),], Species)
12-
integer_encoder <- function(data, feature) {
13+
integer_encoder <- function(data, feature, as_factor = TRUE) {
1314

1415
# Process levels and labels
1516
levels_raw <- data %>%
@@ -33,5 +34,13 @@ integer_encoder <- function(data, feature) {
3334
}
3435
)
3536

37+
if(!as_factor) {
38+
data <- data %>%
39+
dplyr::mutate_at(
40+
.vars = dplyr::vars({{ feature }}),
41+
.funs = as.integer
42+
)
43+
}
44+
3645
return(data)
3746
}

man/integer_encoder.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)