I am importing a csv file into R using the sqldf-package. I have several missing values for both numeric and string variables. I notice that missing values are left empty in the dataframe (as opposed to being filled with NA or something else). I want to replace the missing values with an user defined value. Obviously, a function like is.na() will not work in this case.
Toy dataframe with three columns:
A B C
3 4
2 4 6
34 23 43
2 5
I want:
A B C
3 4 NA
2 4 6
34 23 43
2 5 NA
Thank you in advance.
Assuming you are using
read.csv.sqlinsqldfwith the defaultsqlitedatabase it is producing a factor column for C so(1) just convert the values to numeric using
as.numeric(as.character(...))like this:(2) or if we use
sqldf(..., method = "raw")then we can just useas.numeric:(3) If its feasible for you to use
read.csvthen we do getNAfilling right off: