set integer
set_int(.data, ...)
# S3 method for data.frame
set_int(.data, ...)
# S3 method for grouped_df
set_int(.data, ...)
dataframe
tidyselect. Default Selecton: integerish doubles or integerish characters
tibble
int_vec <- c("1", "2", "10")
tibble::tibble(
chr_int = int_vec,
dbl_int = c(1.0, 5.0, 20.0),
chr_int64 = c("1033493932", "4432500065", "30303022192"),
string_int = c("SALES2020", "SALES2021", "SALES2022")) -> tbl
# automatically coerce integerish cols in a tibble
tbl
#> # A tibble: 3 × 4
#> chr_int dbl_int chr_int64 string_int
#> <chr> <dbl> <chr> <chr>
#> 1 1 1 1033493932 SALES2020
#> 2 2 5 4432500065 SALES2021
#> 3 10 20 30303022192 SALES2022
# integerish doubles or chars will be detected for coercion automatically
tbl %>%
set_int()
#> # A tibble: 3 × 4
#> chr_int dbl_int chr_int64 string_int
#> <int> <int> <int64> <chr>
#> 1 1 1 1033493932 SALES2020
#> 2 2 5 4432500065 SALES2021
#> 3 10 20 30303022192 SALES2022
# string_int requires parsing, so it must be specified directly for coercion
tbl %>%
set_int(matches("str|chr"))
#> some elements containing non-numeric values have been parsed as integers
#> # A tibble: 3 × 4
#> chr_int dbl_int chr_int64 string_int
#> <int> <dbl> <int64> <int>
#> 1 1 1 1033493932 2020
#> 2 2 5 4432500065 2021
#> 3 10 20 30303022192 2022
# s3 method works for vectors as well
int_vec
#> [1] "1" "2" "10"
int_vec %>%
set_int()
#> [1] 1 2 10