janitor学习
#devtools::install_github("sfirke/janitor")
#http://sfirke.github.io/janitor/articles/janitor.html
library(janitor)
test_df <- as.data.frame(matrix(ncol = 6))
names(test_df) <- c("firstName", "ábc@!*", "% successful (2009)",
"REPEAT VALUE", "REPEAT VALUE", "")
#变量名清理
test_df %>%
clean_names()
#列联表
mtcars %>%
tabyl(gear, cyl) %>%
adorn_totals(where = c('row','col')) %>%
adorn_percentages("row") %>%
adorn_pct_formatting(digits = 2) %>%
adorn_ns() %>%
adorn_title()
#获得重复值
get_dupes(mtcars, wt, cyl)
#缺失行列删除
q <- data.frame(v1 = c(1, NA, 3),
v2 = c(NA, NA, NA),
v3 = c("a", NA, "b"))
q %>%
remove_empty(c("rows", "cols"))
#变量值相同列删除
a <- data.frame(good = 1:3, boring = "the same")
a %>% remove_constant()
#excel数字转日期
excel_numeric_to_date(41103)
f <- factor(c("strongly agree", "agree", "neutral", "neutral", "disagree", "strongly agree"),
levels = c("strongly agree", "agree", "neutral", "disagree", "strongly disagree"))
top_levels(f)
#http://sfirke.github.io/janitor/articles/janitor.html
library(janitor)
test_df <- as.data.frame(matrix(ncol = 6))
names(test_df) <- c("firstName", "ábc@!*", "% successful (2009)",
"REPEAT VALUE", "REPEAT VALUE", "")
#变量名清理
test_df %>%
clean_names()
#列联表
mtcars %>%
tabyl(gear, cyl) %>%
adorn_totals(where = c('row','col')) %>%
adorn_percentages("row") %>%
adorn_pct_formatting(digits = 2) %>%
adorn_ns() %>%
adorn_title()
#获得重复值
get_dupes(mtcars, wt, cyl)
#缺失行列删除
q <- data.frame(v1 = c(1, NA, 3),
v2 = c(NA, NA, NA),
v3 = c("a", NA, "b"))
q %>%
remove_empty(c("rows", "cols"))
#变量值相同列删除
a <- data.frame(good = 1:3, boring = "the same")
a %>% remove_constant()
#excel数字转日期
excel_numeric_to_date(41103)
f <- factor(c("strongly agree", "agree", "neutral", "neutral", "disagree", "strongly agree"),
levels = c("strongly agree", "agree", "neutral", "disagree", "strongly disagree"))
top_levels(f)
评论
发表评论