-3

I have dataset with Named "Missing_Values". In that there is column named "city" and some of rows are blank i.e they don't have any city listed there. How can I replace blank values with "NA" in R lang.?

It is like -

ID   Name  Age
1     ram   34
2           46
3    shyam  56
4           87

enter image description here

s__
  • 9,270
  • 3
  • 27
  • 45
shubham
  • 1
  • 4
  • Image is attached . Kindly have a look – shubham Apr 18 '19 at 06:19
  • Did you check: https://stackoverflow.com/questions/24172111/change-the-blank-cells-to-na – Om Sao Apr 18 '19 at 06:21
  • Please share data in a reproducible and copy&paste-able format (using e.g. `dput`). Screenshots are not useful because we can't (easily) extract data/code from an image. – Maurits Evers Apr 18 '19 at 06:21
  • The image you showed is from Excel, but your requesting an R solution. Please read https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and reformat accordingly – Julian_Hn Apr 18 '19 at 06:21
  • It is the snapshot of datatable. .CSV file is imported in R. – shubham Apr 18 '19 at 06:24
  • It is like - ID Name Age 1 ram 34 2 46 3 shyam 56 4 87 – shubham Apr 18 '19 at 06:25

1 Answers1

0

Say you have this data:

Missing_Values <- data.frame(State = sample(c("", 1:9), 10, T), 
                             City = sample(c("", letters[1:9]), 10, T))

If it's only the city column you can do this:

Missing_Values$City[Missing_Values$City==""] <- NA

If it's for all columns:

Missing_Values[Missing_Values==''] <- NA
morgan121
  • 2,213
  • 1
  • 15
  • 33