I would like to replace this typo "-" for NA for a list of df's in R,
I am using the following code, however it throws me an error;
Is there any other way to accomplish this task?
Code
df_list <- lapply(df_list, function(x){
is.na(x) <- x == "-"
x
})
Console Output
Error in charToDate(x) :
character string is not in a standard unambiguous format
data
df1 <- data.frame(a = c(1, 2, "-"), dates = seq(as.Date("2021/01/01"),
as.Date("2021/01/03"),
by = "month"),
strings = c("hello how are you", "hey man", "-"))
df2 <- data.frame(b = c(3,4, "-"),
dates = seq(as.Date("2021/01/01"),
as.Date("2021/01/03"),
by = "month"),
strings = c("hello how are you", "yoooo", "-")
)
df3 <- data.frame(c = c(5, "-", 7),
dates = seq(as.Date("2021/01/01"),
as.Date("2021/01/03"),
by = "month"),
strings = c("hello how are you", "hello world", "-"))
df_list <- list(df1,df2,df3)