Reputation: 31
On this function, I want to replace NA with 0. I try everything on StackOverflow to replace the col argument in the na_replace function. My second line doesn't work. How can I fix this? Note: I tried most of the suggestions posted on StackOverflow, but it doesn't work for me. Col argument is a character, and The rest of the arguments are numeric.
whithout=function(col,min,max,mean,sd){
col=as.String(col)
continuous_dataset%>%replace_na(list(sym(col=0)))
number=which(colnames(continuous_dataset)==col)
for(i in 1:4267){
if(continuous_dataset[i,number]==0){
continuous_dataset[i,number]=round(rtruncnorm(1,min,max,mean,sd))
}
}
}
Upvotes: 0
Views: 36
Reputation:
I have isolated the part of the workflow that is specific to your question about using replace_na()
. For this, you can use setNames()
to create the named list.
library(tidyr)
# example dataset
mtcars_na <- mtcars
mtcars_na$mpg[3] <- NA
# character column names
col <- "mpg"
# create the named list for use in replace_na
mtcars_na %>%
replace_na(setNames(list(0), col))
Upvotes: 1