I'd like to transform multiple variables into a discrete form using quantcut.
library(gtools)
library(dplyr)
quantcut(df$var3, q=4, na.rm = TRUE)
Works.
Now I'd like to apply this formula to multiple variables. What I have is something like this:
var_col <- c(var3, var4, var5, var6)
df <- df %>%
mutate(across(all_of(var_col), quantcut(., q=4, na.rm = TRUE, .names = "cut_{col}"))
This yields me the error: "x can't combine year
and country
. The error occurred in group one: year = 1800.
The dataset looks something like this:
country <- c("GER", "ITA", "FRA")
year <- c("1800", "1801", "1802")
var3 <- c(1L, 2L, 3L)
var4 <- c(3L, 4L, 5L)
var5 <- c(6L, 7L, NA)
var6 <- c(8L, 9L, 10)
df <- data.frame(country, year, var3, var4, var5, var6)
Though I should say that with the reprex I tried making I got a different error: "x non-numeric argument to binary operator" so I guess the variable type is different, I'll try and find a way to exactly replicate my error.