[R-pkgs] Repost: New CRAN package: hablar
David sjöberg
d@v@@job @ending from gm@il@com
Mon Nov 5 21:03:16 CET 2018
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:
install.packages("hablar")
library(hablar)
1. convert()
mtcars %>%
convert(num(vs),
int(am, gear),
chr(cyl:drat))
this simple code chunk converts column 'vs' to numeric,
'am' and 'gear' to integer and 'cyl' through 'drat' to character.
2. retype()
mtcars <- mtcars %>%
convert(chr(everything()))
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:
https://cran.r-project.org/web/packages/hablar/readme/README.html
https://github.com/davidsjoberg/hablar
https://davidsjoberg.github.io/blog/
Happy coding!
David
More information about the R-packages
mailing list