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 x_z and y_z
df_scaled <- df_test %>%
mutate(across(everything(), scale, .names = "{.col}_z"))
# Output
df_scaled
#> # A tibble: 4 × 4
#> x y x_z[,1] y_z[,1]
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 5 -1.16 -1.16
#> 2 2 6 -0.387 -0.387
#> 3 3 7 0.387 0.387
#> 4 4 8 1.16 1.16
Expected output
#> # A tibble: 4 × 4
#> x y x_z y_z
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 5 -1.16 -1.16
#> 2 2 6 -0.387 -0.387
#> 3 3 7 0.387 0.387
#> 4 4 8 1.16 1.16
Created on 2022-12-30 with reprex v2.0.2