mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2026-06-19 13:17:30 +02:00
Deploying to gh-pages from @ agdamsbo/REDCapCAST@db75c3313e 🚀
This commit is contained in:
parent
bc2e23a272
commit
0b30252598
171 changed files with 7009 additions and 602 deletions
42
reference/var2fct.md
Normal file
42
reference/var2fct.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Convert vector to factor based on threshold of number of unique levels
|
||||
|
||||
This is a wrapper of forcats::as_factor, which sorts numeric vectors
|
||||
before factoring, but levels character vectors in order of appearance.
|
||||
|
||||
## Usage
|
||||
|
||||
``` r
|
||||
var2fct(data, unique.n)
|
||||
```
|
||||
|
||||
## Arguments
|
||||
|
||||
- data:
|
||||
|
||||
vector or data.frame column
|
||||
|
||||
- unique.n:
|
||||
|
||||
threshold to convert class to factor
|
||||
|
||||
## Value
|
||||
|
||||
vector
|
||||
|
||||
## Examples
|
||||
|
||||
``` r
|
||||
sample(seq_len(4), 20, TRUE) |>
|
||||
var2fct(6) |>
|
||||
summary()
|
||||
#> 1 2 3 4
|
||||
#> 7 5 6 2
|
||||
sample(letters, 20) |>
|
||||
var2fct(6) |>
|
||||
summary()
|
||||
#> Length Class Mode
|
||||
#> 20 character character
|
||||
sample(letters[1:4], 20, TRUE) |> var2fct(6)
|
||||
#> [1] c b b a d d c d d c b b c d b b b a a c
|
||||
#> Levels: c b a d
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue