I'm facing a problem that I cannot fix. I have not a lot experience in R so any help will be welcome.
Okay so I have a variable called supermarkt2015_afst
which is the distance to the supermarket. It goes from 0.1 towards 99.9. km.
However the variable contains some MISSING values.
Since the fields are literally called "MISSING"
and I don't want anything above 100km I clean it by;
datamodel2 <- datamodel2 %>% mutate(supermarkt2015_afst=ifelse(supermarkt2015_afst=="MISSING",NA,supermarkt2015_afst))
datamodel2 <- datamodel2 %>% mutate(supermarkt2015_afst=ifelse(supermarkt2015_afst>100,NA,supermarkt2015_afst))
datamodel2 <- datamodel2 %>% filter(!is.na(supermarkt2015_afst))
This cleans indeed the MISSING values and throws away roughly a third of my observations. Which is exactly what I wanted. HOWEVER. The variable now goes from 2-99. Not like 2.1 2.2 2.3, only round numbers. Where did it all go wrong? It says my variable is Integer when I run "typeof". What i want is have the same accuracy as before on 1 decimal. But for some reason it alters my variable as well.
One variable in my data looks like
dput(head(datamodel2$supermarkt2015_afst))
structure(c(3L, 3L, 3L, 3L, 3L, 3L), .Label = c("0,1", "0,2", "0,3", "0,4", "0,5",
"0,6", "0,7", "0,8", "0,9", "1,0", "1,1", "1,2", "1,3", "1,4",
"1,5", "1,6", "1,7", "1,8", "1,9", "10,0", .............. "6,4", "6,5", "6,6",
"6,7", "6,8", "6,9", "7,0", "7,1", "7,2", "7,3", "7,4", "7,5", "7,6", "7,7",
"7,8", "7,9", "8,0", "8,1", "8,2", "8,3", "8,6", "8,9", "9,0", "9,1", "9,2",
"9,3", "9,6", "MISSING"), class = "factor")