Force tabyl to show even columns with all 0 as values

Advertisements The tabyl function from the janitor package generates a frequency table of the specified variables. By default, it excludes missing values from the output. Let’s say I have the following dataframe: df <- data.frame( var_1 = c(rep("ja",7),rep("nein",13)), var_2 = c(31:50), var_3 = c(rep(0,10),rep(1,10))) Then the output of tabyl will be like: library(janitor) df %>%… Read More Force tabyl to show even columns with all 0 as values

Creating a col that adds a numeric value based on the order of a character string in R

Advertisements I have responses where I solicited rankings of issues and the response I have for each individual look like this: structure(list(Rank = "Shifting angler preferences and behaviors;Increasing effort and fishing power;R3 (Recruitment, Retention, and Reactivation);Economic impacts;Climate change;"), row.names = c(NA, -1L), class = "data.frame") I am trying to create a column that gives the… Read More Creating a col that adds a numeric value based on the order of a character string in R

How to insert rows in specific indices of dataframe containing sum of few rows above only in R pipe dplyr

Advertisements for dataframe below, df <- data.frame(id = c(rep(101, 4), rep(202, 3)), status = c("a","b","c","d", "a", "b", "c"), wt = c(100,200,100,105, 20,22,25), ht = c(5.3,5.2,5,5.1, 4.3,4.2,4.1)) df id status wt ht 1 101 a 100 5.3 2 101 b 200 5.2 3 101 c 100 5.0 4 101 d 105 5.1 5 202 a 20… Read More How to insert rows in specific indices of dataframe containing sum of few rows above only in R pipe dplyr

Replace all occurrences of columns in a data frame

Advertisements I have two columns Project ID and Project Number in my dataframe hpds_all_clean with NAs in them, and I’m trying to replace all NAs occurrences with "Undisclosed Project ID" and "Undisclosed Project Number". Here are some of my attempts which have the same error: target of assignment expands to non-language object Using gsub(): hpds_all_clean… Read More Replace all occurrences of columns in a data frame