I need help with replacing '?' on my data frame with Zeros in R language.
any help will be highly appreciated. Regards
df <- data.frame(
A=c(1,"?",3),
B=c(1:3),
C=c("a", "b", "?")
)
df <- apply(df, MARGIN = 2, FUN = function(x) {
x[x == "?"] <- 0
x
})
as.data.frame(df)
# A B C
# 1 1 1 a
# 2 0 2 b
# 3 3 3 0