I have a csv
file with country names and their iso codes. Here's what it looks like:
"Name","Code"
"Afghanistan","AF"
"Albania","AL"
"Algeria","DZ"
"Namibia","NA"
I read it in a data.frame
using the following code:
cc = read.csv("countries.csv", header=TRUE, stringsAsFactors=FALSE,
colClasses = c("character"))
Here's what the data looks like:
Name Code
Afghanistan AF
Albania AL
Algeria DZ
Namibia <NA>
The string "NA"
is getting converted to <NA>
even though I explicitly set colClasses = c("character")
.
How do I get "NA"
to show as "NA"
in the data.frame
?
Try setting the na.strings
parameter explicitly - the default is"NA":
cc = read.csv("countries.csv", header=TRUE, stringsAsFactors=FALSE,
colClasses = c("character"), na.strings="" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With