-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datawizard versions of separate() and unite() #423
Comments
I think |
library(datawizard)
d <- data.frame(
x = c(NA, 1:3),
y = c(letters[1:3], NA_character_),
z = 6:9,
m = c("X", NA_character_, "Y", "Z")
)
d
#> x y z m
#> 1 NA a 6 X
#> 2 1 b 7 <NA>
#> 3 2 c 8 Y
#> 4 3 <NA> 9 Z
data_unite(d, new_column = "xyz")
#> xyz
#> 1 NA_a_6_X
#> 2 1_b_7_NA
#> 3 2_c_8_Y
#> 4 3_NA_9_Z
data_unite(d, new_column = "xyz", remove_na = TRUE)
#> xyz
#> 1 a_6_X
#> 2 1_b_7
#> 3 2_c_8_Y
#> 4 3_9_Z
data_unite(d, new_column = "x")
#> x
#> 1 NA_a_6_X
#> 2 1_b_7_NA
#> 3 2_c_8_Y
#> 4 3_NA_9_Z
data_unite(d, new_column = "x", remove_na = TRUE)
#> x
#> 1 a_6_X
#> 2 1_b_7
#> 3 2_c_8_Y
#> 4 3_9_Z
data_unite(d, new_column = "x", append = TRUE)
#> The name for `new_column` already exists as variable name in the data.
#> This variable will be replaced by `new_column`.
#> x y z m
#> 1 NA_a_6_X a 6 X
#> 2 1_b_7_NA b 7 <NA>
#> 3 2_c_8_Y c 8 Y
#> 4 3_NA_9_Z <NA> 9 Z
data_unite(d, new_column = "x", remove_na = TRUE, append = TRUE)
#> The name for `new_column` already exists as variable name in the data.
#> This variable will be replaced by `new_column`.
#> x y z m
#> 1 a_6_X a 6 X
#> 2 1_b_7 b 7 <NA>
#> 3 2_c_8_Y c 8 Y
#> 4 3_9_Z <NA> 9 Z
data_unite(d, new_column = "xyz", append = TRUE)
#> x y z m xyz
#> 1 NA a 6 X NA_a_6_X
#> 2 1 b 7 <NA> 1_b_7_NA
#> 3 2 c 8 Y 2_c_8_Y
#> 4 3 <NA> 9 Z 3_NA_9_Z
data_unite(d, new_column = "xyz", remove_na = TRUE, append = TRUE)
#> x y z m xyz
#> 1 NA a 6 X a_6_X
#> 2 1 b 7 <NA> 1_b_7
#> 3 2 c 8 Y 2_c_8_Y
#> 4 3 <NA> 9 Z 3_9_Z
data_unite(d, new_column = "x2")
#> x2
#> 1 NA_a_6_X
#> 2 1_b_7_NA
#> 3 2_c_8_Y
#> 4 3_NA_9_Z
data_unite(d, select = c("x", "z"), new_column = "new")
#> y m new
#> 1 a X NA_6
#> 2 b <NA> 1_7
#> 3 c Y 2_8
#> 4 <NA> Z 3_9
data_unite(d, select = c("x", "z"), new_column = "new", append = TRUE)
#> x y z m new
#> 1 NA a 6 X NA_6
#> 2 1 b 7 <NA> 1_7
#> 3 2 c 8 Y 2_8
#> 4 3 <NA> 9 Z 3_9
data_unite(d, select = c("x", "z"), new_column = "new", append = TRUE, remove_na = TRUE)
#> x y z m new
#> 1 NA a 6 X 6
#> 2 1 b 7 <NA> 1_7
#> 3 2 c 8 Y 2_8
#> 4 3 <NA> 9 Z 3_9
data_unite(d, new_column = "xyz", separator = ".")
#> xyz
#> 1 NA.a.6.X
#> 2 1.b.7.NA
#> 3 2.c.8.Y
#> 4 3.NA.9.Z Created on 2023-05-25 with reprex v2.0.2 |
@jmgirard |
I'm hoping to retool my packages soon to use datawizard instead of dplyr and tidyr. However, a few things I need that don't seem to exist yet are datawizard versions of separate() and unite() from tidyr. Any plans to create these?
The text was updated successfully, but these errors were encountered: