-2

I'm playing with a .csv file that has some "unknown" values that I have to clear in R. For example, column A has variables "yes", "no", and "unknown"

How can I get rid of the "unknown" variables using R code.

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • 4
    `read.csv` has a parameter named `na.strings` which you should set to "unknown`. – IRTFM Apr 09 '18 at 23:09
  • 2
    Welcome to SO! Please provide a [reproducible question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can see some sample data. Other good ref links include https://stackoverflow.com/help/how-to-ask and https://stackoverflow.com/help/mcve. Please read them, then come back and edit your question. – r2evans Apr 09 '18 at 23:10
  • Possible duplicate of [how to use "NA" as string](https://stackoverflow.com/questions/33126182/how-to-use-na-as-string) – Cristian E. Nuno Apr 09 '18 at 23:44

1 Answers1

1

As far as I got your questions you try to define Cellvalues that are "unknown" as an NA in your data frame. You can do this by setting the na.string in your read.csv() function.

df <- read.csv(file, na.strings = "unknown") 

and that's it! Now you should have a new data frame that declares "unknown" as NA.

Cristian E. Nuno
  • 2,822
  • 2
  • 19
  • 33
Marcel Der
  • 171
  • 1
  • 4