Combining mutate, across, and as_date('yyyymmdd') results in all NA

I’m trying to combine mutate, across, and as_date, including the format argument in as_date. This is resulting in all NA values, as shown below. library(tidyverse) library(tis) holidays(2023) %>% data.frame() %>% set_names(‘holiday_date’) %>% rownames_to_column() %>% pivot_wider(names_from = rowname,values_from = holiday_date) %>% mutate(across(everything(), as.character)) %>% mutate(across(everything(), #as_date # WORKS ~as_date(.,format="yyyymmdd") # DOESN’T WORK )) This results in… Read More Combining mutate, across, and as_date('yyyymmdd') results in all NA

str_replace inside fct_reorder inside mutate(across())

Say I have this tibble: df <- tibble::tribble( ~how_bright_txt, ~how_bright_num, ~how_hard_txt, ~how_hard_num, ~how_hot_txt, ~how_hot_num, "Not very much", 1L, "Really hard", 5L, "Cold", 1L, "Somewhat", 2L, "Somewhat hard", 2L, "A bit cold", 2L, "Medium", 3L, "Medium", 3L, "Medium", 3L, "Quite a bit", 4L, "Quite hard", 4L, "Quite hot", 4L, "A lot", 5L, "Not very hard", 1L,… Read More str_replace inside fct_reorder inside mutate(across())

How can I mutate across all columns of a dataframe using a function like separate that seems to be expecting a dataframe instead of a vector?

I have a dataframe where I would like to separate each column into two columns. Each column follow the same pattern "x_y" test <- structure(list(A = c("511686_0.112", "503316_0.105", "476729_0.148", "229348_0.181", "385774_0.178", "209277_0.029", "299921_0.124", "486771_0.123", "524146_0.07", "496030_0.119"), B = c("363323_0.103", "260709_0.105", "361361_0.148", "731426_0.181", "222799_0.178", "140296_0.029", "388191_0.124", "500136_0.123", "487344_0.07", "267303_0.119"), C = c("362981_0.103", "260261_0.105", "360912_0.148", "730423_0.181", "222351_0.178",… Read More How can I mutate across all columns of a dataframe using a function like separate that seems to be expecting a dataframe instead of a vector?

mutate across columns with ifelse

I’m trying to mutate values across multiple columns to values from another column. This is my dataset: library(stringr) library(dplyr) library(fastDummies) score <- sample(1:100,20,replace=TRUE) df <- data.frame(score) df <- df %>% mutate(grp = cut(score, breaks = c(-Inf, seq(0, 100, by = 20), Inf)), grp = str_c("G", as.integer(droplevels(grp)), ‘_’, str_replace(grp, ‘\\((\\d+),(\\d+)\\]’, ‘\\1_\\2’))) %>% dummy_cols("grp", remove_selected_columns = TRUE)… Read More mutate across columns with ifelse

In dplyr how do you filter to remove NA values from columns in a character vector?

I’d like to remove rows with NA in any one of the columns in a vector of column names. Here’s a simplified example with just a couple of columns. data <- structure(list(sample_id = c("2023.01.12_2", "2023.01.12_27", "2023.01.12_27", "2023.01.12_3", "2023.01.12_27", "2023.01.12_27", "2023.01.12_4", "2023.01.12_27", "2023.01.12_27", "2023.01.12_5" ), group = c("Unedited", "Rob", "Rob", "Partial_promoter", "Rob", "Rob", "Promoter_and_ATG", "Rob", "Rob",… Read More In dplyr how do you filter to remove NA values from columns in a character vector?

Why mutate + across in dplyr create columns with "[,1]" at the end?

See code below. the mutate(across(everything(), scale, .names = "{.col}_z")) part of the syntax is generating columns with [,1]appended at the end. Two questions: Why is this happening? How can I avoid or remove it? library(dplyr) # Input df_test <- tibble(x = c(1, 2, 3, 4), y = c(5, 6, 7, 8)) # My code generating… Read More Why mutate + across in dplyr create columns with "[,1]" at the end?