-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.Rmd
More file actions
59 lines (40 loc) · 1.35 KB
/
Copy pathREADME.Rmd
File metadata and controls
59 lines (40 loc) · 1.35 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
## Installation
```{r}
#install_github("zhamel/foo")
library(foo)
```
## Usage
This package consists of 4 functions which hopefully can make your life easier when dealing with factors.
### `fbind()`
**Goal**: Bind two factors together to get back a factor with the levels from both factors.
```{r}
fbind(iris$Species[c(1, 51, 101)], PlantGrowth$group[c(1, 11, 21)])
```
### `freq_out()`
**Goal**: Create a data frame consisting of the levels of the factor and its frequency.
```{r}
freq_out(iris$Species)
```
### `reorder_levels()`
**Goal**: Reordering the levels based on frequency (from least to most)
```{r}
reorder_levels(factor(c("a","a","b","c","c","c","c","d","d","d")))
```
### `factor_to_char()`
**Goal**: Should your factor be a character instead? This function compares the length of the factor with the number of levels. If the length of the factor = # of levels of the factor, then `factor_to_char()` returns `TRUE`: maybe this shouldn't be a factor! Otherwise, if they are different, `factor_to_char()` returns `FALSE`: this time you may want to keep it as a factor!
```{r}
factor_to_char(iris$Species)
```