Skip to content

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
msberends committed Jun 1, 2020
1 parent cc6e8ae commit 601c5f3
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 89 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: cleaner
Title: Fast and Easy Data Cleaning
Version: 1.4.0.9000
Date: 2020-05-28
Version: 1.5.0
Date: 2020-06-01
Authors@R:
person(
given = c("Matthijs", "S."),
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cleaner 1.4.0.9000
# cleaner 1.5.0

* New function `format_names()` to quickly and easily change names of `data.frame` columns, `list`s or `character` vectors.
```r
Expand Down Expand Up @@ -26,6 +26,7 @@
starwars %>%
na_replace() # replace NAs in all columns ("" for hair_color and 0 for birth_year)
```
* Support for the upcoming R 4.1.0

# cleaner 1.4.0

Expand Down
2 changes: 1 addition & 1 deletion R/na_replace.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ na_replace.data.frame <- function(x, ..., replacement = NULL) {
if (vctr_colname %in% colnames(attrbt$groups)) {
attrbt$groups[which(is.na(attrbt$groups[, vctr_colname, drop = TRUE])), vctr_colname] <- replace_val
# groups are always ordered on alphabet, so order it again with the new replacement value
attrbt$groups <- attrbt$groups[order(attrbt$groups[, vctr_colname]),]
attrbt$groups <- attrbt$groups[order(attrbt$groups[, vctr_colname]), ]
}
}
}
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,49 @@ Use `clean()` to clean data. It guesses what kind of data class would best fit y
#> 2 31.40
```

#### Other cleaning

* Use `format_names()` to quickly and easily change names of `data.frame` columns, `list`s or `character` vectors.
```r
format_names(df, snake_case = TRUE)
format_names(df, c(old.name = "new_name", value = "measurement"))

library(dplyr)
starwars %>%
format_names(camelCase = TRUE) %>% # changes column names
mutate(name = name %>%
format_names(snake_case = TRUE)) # changes values in column
```

* Use the generic function `na_replace()` to replace `NA` values in any data type. Its default replacement value is dependent on the data type that is given as input: `0` for numeric values and class `matrix`, `FALSE` for class `logical`, today for class `Date`, and `""` otherwise.

```r
na_replace(c(1, 2, NA, NA))
#> [1] 1 2 0 0
na_replace(c(1, 2, NA, NA), replacement = -1)
#> [1] 1 2 -1 -1
na_replace(c(1, 2, NA, NA), replacement = c(0, -1))
#> [1] 1 2 0 -1

na_replace(c("a", "b", NA, NA))
#> [1] "a" "b" "" ""
```

It also supports replacing `NA`s in complete data sets and supports grouped variables used by the `dplyr` package:

```r
library(dplyr)
starwars %>%
na_replace(hair_color) # only replace NAs in this column

starwars %>%
na_replace() # replace NAs in all columns ("" for hair_color and 0 for birth_year)

starwars %>%
group_by(hair_color) %>%
na_replace(hair_color, replacement = "TEST!") %>%
summarise(n = n())
```

### Checking

Expand Down
4 changes: 2 additions & 2 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 51 additions & 10 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 601c5f3

Please sign in to comment.