[R-pkgs] Repost: New CRAN package: hablar

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[R-pkgs] Repost: New CRAN package: hablar

David sjöberg
Dear R-users,

The new package hablar help R-users to convert columns to new data types.
Also helps with summary functions like min and mean with vectors that contain NA, Inf, NaN or when they are empty.

Three functions you may consider to use:

1. convert()

mtcars %>%
          int(am, gear),

this simple code chunk converts column 'vs' to numeric,
'am' and 'gear' to integer and 'cyl' through 'drat' to character.

2. retype()

mtcars <- mtcars %>%

mtcars %>% retype()

This function is for us lazy R-programmers. It converts columns
to the simplest data type possible, without loosing information.

3. s()

min(c()) # base R returns Inf
min(s(c())) # with s it returns NA

max(c(NaN, Inf)) # base R returns NaN
max(s(c(NaN, Inf))) # with s it returns NA

mean(c(NA, 2, 4, NA)) # base R returns NA
mean(c(NA, 2, 4, NA), na.rm = TRUE) # base R with na.rm = T returns 3
mean(s(c(NA, 2, 4, NA))) # with s it returns 3 without using na.rm = TRUE
mean_(c(NA, 2, 4, NA)) # s-wrapper mean_  returns 3

s always returns a real value, otherwise NA. This helps you
avoid the problem of getting Inf when trying to minimize
empty or vectors with infinite or NaN values. You can also skip na.rm = T
to simplify code syntax.

More information on hablar:
Happy coding!

R-packages mailing list
[hidden email]

[hidden email] mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.