[R-pkgs] New CRAN package: hablar
David sjöberg
d@v@@job @ending from gm@il@com
Sun Nov 4 22:44:13 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), na.rm = TRUE) # base R returns NA
mean(c(NA, 2, 4, NA)) # base R returns 3
mean(s(c(NA, 2, 4, NA))) # with s it returns 3 without using na.rm = TRUE
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