Convert Data Types and Get Non-Astonishing Results

Simple tools for converting columns to new data types. Intuitive summary functions.


hablar give users an easy and effective way to work with data types. Additionally, it provides non-astonishing results when summarizing data.

The ambition is to lower the barrier to R but also provides simple tools that experienced R users could benefit from.

Installation

You can install hablar from github with:

devtools::install_github("davidsjoberg/hablar")

convert

The most useful function of hablar is maybe convert. convert helps the user to quickly change data type of columns in a data frame. convert always converts factors to character before further conversion.

## convert column:
# gear, vs to integers (int)
# cyl to factor (fct)
# am, gear and carb to character (chr)
mtcars %>% 
  convert(int(gear, vs),
          fct(cyl),
          chr(am, gear, carb))
#> # A tibble: 32 x 11
#>     mpg cyl    disp    hp  drat    wt  qsec    vs am    gear  carb 
#>   <dbl> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <chr> <chr> <chr>
#> 1  21   6       160   110  3.9   2.62  16.5     0 1     4     4    
#> 2  21   6       160   110  3.9   2.88  17.0     0 1     4     4    
#> 3  22.8 4       108    93  3.85  2.32  18.6     1 1     4     1    
#> 4  21.4 6       258   110  3.08  3.22  19.4     1 0     3     1    
#> # ... with 28 more rows

For more information type vignette("convert") in the console.

retype

A function for quick and dirty data type conversion. All columns are evaluated and converted to the simplest possible without loosing any information.

## convert all columns to character
df <- mtcars %>% convert(chr(everything()))
df
#> # A tibble: 32 x 11
#>   mpg   cyl   disp  hp    drat  wt    qsec  vs    am    gear  carb 
#>   <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 21    6     160   110   3.9   2.62  16.46 0     1     4     4    
#> 2 21    6     160   110   3.9   2.875 17.02 0     1     4     4    
#> 3 22.8  4     108   93    3.85  2.32  18.61 1     1     4     1    
#> 4 21.4  6     258   110   3.08  3.215 19.44 1     0     3     1    
#> # ... with 28 more rows
## let retype guess the best data type
df %>% retype()
#> # A tibble: 32 x 11
#>     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>   <dbl> <int> <dbl> <int> <dbl> <dbl> <dbl> <int> <int> <int> <int>
#> 1  21       6   160   110  3.9   2.62  16.5     0     1     4     4
#> 2  21       6   160   110  3.9   2.88  17.0     0     1     4     4
#> 3  22.8     4   108    93  3.85  2.32  18.6     1     1     4     1
#> 4  21.4     6   258   110  3.08  3.22  19.4     1     0     3     1
#> # ... with 28 more rows

For more information type vignette("retype") in the console.

s

Often summary function like min, max and mean return suprising results. Combining s with your summary function ensures you that you will get a result, if there is one in your data.

## Base R
x <- c(NaN, 1, 2, NA)
min(x)
#> [1] NA
## With s
min(s(x))
#> [1] 1

For more information type vignette("s") in the console.

Note

Hablar means 'speak R' in spanish.

News

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("hablar")

0.1.0 by David Sjoberg, 3 months ago


https://davidsjoberg.github.io/


Report a bug at https://github.com/davidsjoberg/hablar/issues


Browse source code at https://github.com/cran/hablar


Authors: David Sjoberg


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports dplyr

Suggests testthat, knitr, rmarkdown, gapminder, DiagrammeR


See at CRAN