Questions tagged [janitor]

Use this tag for questions related to the janitor package. The janitor package provides functions to make it easy to examine and clean data in the R programming language.

89 questions
9
votes
3 answers

Convert Excel numeric to date

I have a vector of numeric excel dates i.e. date <- c(42963,42994,42903,42933,42964) The output am I expecting when using excel_numeric_to_date function from janitor package and as.yearmon function from zoo…
Azam Yahya
  • 646
  • 1
  • 7
  • 10
7
votes
2 answers

How to collapse rows of a frequency table to add their counts in a new column?

I have a dataframe with sample classifications: Seq_ID Family Father Mother Sex Role Type 1 SSC02219 11000. 0 0 Male Father Parent 2 SSC02217 11000. 0 …
Carmen Sandoval
  • 2,266
  • 5
  • 30
  • 46
5
votes
2 answers

Calculate and append column totals of select columns in a dataframe

I have the following code for calculating certain quantities of interest, specifically the sum of the two right-most columns. library(dplyr) library(janitor) m = c(0, 0.8, 2.3, 4.1, 2.1) l = c(0.3, 0.8, 0.9, 0.75, 0.25) mytable = data.frame(l,…
NM_
  • 1,887
  • 3
  • 12
  • 27
4
votes
3 answers

Loop Over Multiple Environment Objects R

I want to be able to loop over multiple objects in my environment and do some data cleaning on each data frame. Is there a more efficient way to do what I am doing below in 1 call? df1 %>% clean_names() df2 %>% clean_names() df3…
bodega18
  • 596
  • 2
  • 13
4
votes
2 answers

Suppress missing values in Tabyl xtabs in R

According to the tabyl documentation: However, I can't figure out how to suppress the NA from the denominator! Please see here for the data: df <- data.frame(col1 = c(1,1,2,2,1, NA,NA), col2 = c("this", NA,"is",…
NewBee
  • 990
  • 1
  • 7
  • 26
4
votes
4 answers

tidyverse: Cross tables of one variable with all other variables in data.frame

I want to make cross table of a variable with all other variables in the data.frame. library(tidyverse) library(janitor) humans <- starwars %>% filter(species == "Human") humans %>% janitor::tabyl(gender, eye_color) gender blue blue-gray…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
3
votes
1 answer

Specify the calculation by column using adorn_totals()

I am trying to add a totals row usin ghte Janitor package in R, however I need 2 columns to be totaled using the sum function and one column to be a percentage (not the sum of the column). library(tidyverse) library(janitor) df.1 <-…
cowboy
  • 613
  • 5
  • 20
3
votes
2 answers

Pass arguments to ellipsis(...) in adorn_totals

How could I pass what columns should adorn_totals consider without passing another arguments. library(dplyr) library(janitor) mtcars %>% count(vs,am) %>% adorn_totals() #> vs am n #> 0 0 12 #> 0 1 6 #> 1 0 7 #> 1…
M Aurélio
  • 830
  • 5
  • 13
3
votes
3 answers

How to exclude percentages from Total column and row when using janitor::adorn_percentages()

Is there any way I can get the output below directly from adorn functions? library(janitor) library(stringr) df <- mtcars %>% tabyl(am, cyl) %>% adorn_totals(c("row", "col")) %>% adorn_percentages("row") %>% adorn_pct_formatting(digits = 2)…
Mathica
  • 1,241
  • 1
  • 5
  • 17
3
votes
1 answer

Using base::function with tidyverse and janitor to create several crosstables in R

I have a Data Frame with Survey Data and want to create crosstables between every dimension and diagnosis. I succesfully did this with dplyr and janitor: library(tidyverse) library(janitor) survey <- tibble(dimension_1 = c(1, NA, 2, 3, 1, 1, 1, 3,…
Ntgllr
  • 85
  • 6
3
votes
8 answers

Compare multiple columns from a dataframe with an outer vector

Say we have this vector: products <- c(a, b, d, f, g, h, i, j, m, o, t, z) And a dataframe like this one below: seller_a seller_b seller_c a b d d d e g g g h l h t n t z …
teogj
  • 289
  • 1
  • 11
3
votes
3 answers

Find and keep duplicated items in each column in R

Is there any way I can use some like tidyverse's add_count() %>% filter() or distinct() or alternatively janitor's get_dupes() to find and keep the duplicated items of each column. No need to compare items of different columns with each other, each…
mike
  • 49
  • 4
3
votes
1 answer

Run multiple crosstabs using tabyl

I have data such as this: dat <- mtcars %>% mutate(cyl2 = cyl*2,cyl3 = cyl*3) I would like to run each of the following cross tabs [vs,cyl] [vs,cyl1] [vs,cyl2] [vs,cyl3] using tabyl: I know that I can run vs, cyl such as this, and repeat this…
NewBee
  • 990
  • 1
  • 7
  • 26
3
votes
1 answer

How to use lapply with a list of columns passing to a 2-way tabyl

I'm trying to use lapply() to create multiple crosstabs, using the tabyl() function which I really like and am comfortable with. I prefer it in this format so that I can go on to do other things with it. However, I can only get lapply() to work with…
A. Piong
  • 192
  • 1
  • 11
3
votes
2 answers

Iterate over specified columns for crosstabs in R

I am looking to run a couple of dozen crosstabs within the same dataset and with a set outcome variable. I have a function that gives me the crosstabs I want: second_table = function(dat, variable1, variable2){ dat %>% tabyl({{variable1}},…
Emily Halford
  • 169
  • 1
  • 7
1
2 3 4 5 6