I'm new to R and I'm trying to find all the missing values in my data set. I'm using R and I tried the is.na function and it didn't work. Missing entries in my dataset have a "?"
Asked
Active
Viewed 44 times
-4
-
Try `df=="?"`.. – user2974951 Feb 11 '21 at 07:14
-
Hi sorry thanks for that. What will df=="?" do? – user15161304 Feb 11 '21 at 07:17
-
Okay! That worked for the first row, do you know how I can get it to run for all rows? – user15161304 Feb 11 '21 at 07:18
-
If you have used `read.table` to import your data.frame, then you can use set `na.strings = "?"`. – zx8754 Feb 11 '21 at 08:37
1 Answers
0
df[df=="?"] <- NA

zimia
- 930
- 3
- 16
-
Hey thanks for this. Tried that and nothing executed. Am I missing something? – user15161304 Feb 11 '21 at 07:24
-
Hey if you run this line, your df should now have NA instead of "?". Then you can use na.omit(df) to remove the rows that contain NAs or use replace_na to replace the NAs with anything else you want by column. df %>% tidyr::replace_na(list(column_name=0)) for example will replace NA with 0 in the column called "column_name" – zimia Feb 11 '21 at 07:27