Revisión | 3e3aabb1b1adc61c38d5cf6b3fdd9359c6078799 (tree) |
---|---|
Tiempo | 2023-01-20 02:36:12 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I made some modifications to get ready for the new dplyr release.
@@ -2779,8 +2779,13 @@ | ||
2779 | 2779 | |
2780 | 2780 | ## res <- df %>% replace(., is.na(.), pattern) |
2781 | 2781 | |
2782 | + ## res <- df |> | |
2783 | + ## (\(x) replace(x, is.na(x), pattern))() | |
2784 | + | |
2785 | + | |
2782 | 2786 | res <- df |> |
2783 | - (\(x) replace(x, is.na(x), pattern))() | |
2787 | + mutate(across(everything(),\(x) replace(x, is.na(x), pattern))) | |
2788 | + | |
2784 | 2789 | |
2785 | 2790 | return(res) |
2786 | 2791 |
@@ -2834,13 +2839,18 @@ | ||
2834 | 2839 | |
2835 | 2840 | ## the other way around, consider a certain pattern as an NA |
2836 | 2841 | |
2842 | +## See https://github.com/tidyverse/dplyr/issues/6645#issuecomment-1397035215 | |
2843 | + | |
2837 | 2844 | pattern_to_na <- function(df, pattern){ |
2838 | 2845 | |
2839 | 2846 | ## res <- df %>% na_if(., pattern) |
2840 | 2847 | |
2841 | -res <- df |> (\(x) na_if(x, pattern))() | |
2842 | - | |
2843 | - | |
2848 | +## res <- df |> (\(x) na_if(x, pattern))() | |
2849 | + | |
2850 | +## across(where(is.character), \(x) na_if(x, "D")) | |
2851 | + | |
2852 | + res <- df |> | |
2853 | + mutate(across(where(is.character), \(x) na_if(x, pattern))) | |
2844 | 2854 | |
2845 | 2855 | return(res) |
2846 | 2856 |
@@ -2856,8 +2866,12 @@ | ||
2856 | 2866 | |
2857 | 2867 | if (!is.na(pattern1)){ |
2858 | 2868 | |
2859 | -res <- df |> (\(x) replace(x,x== pattern1, pattern2))() | |
2860 | - | |
2869 | +## res <- df |> (\(x) replace(x,x== pattern1, pattern2))() | |
2870 | + | |
2871 | + res <- df |> | |
2872 | + mutate(across(where(is.character), \(x) replace(x,x== pattern1, pattern2))) | |
2873 | + | |
2874 | + | |
2861 | 2875 | } else{ |
2862 | 2876 | |
2863 | 2877 |