0

I am reading quite a number of .csv files originating from Excel, into R. Some cells contain the value '#NUM!', which I guess results from dividing by zero. In any case, R does not like it. And since I have many files, I would like to replace the #NUM! values with NA as I import the file into R. Instead of going through every file doing seek-replace.

Suggestion is appreciated. Thanks.

jd

SigneMaten
  • 493
  • 1
  • 6
  • 13

1 Answers1

5

read.csv has an argument called na.strings which enables you to interpret which values shall be considered as NA. Try that.

Example:

> read.csv("nana.csv")
     X1    X2    X3
1     1 #NUM!     4
2     2     4 #NUM!
3 #NUM! #NUM! #NUM!

> read.csv("nana.csv",na.strings="#NUM!")
  X1 X2 X3
1  1 NA  4
2  2  4 NA
3 NA NA NA
Spacedman
  • 92,590
  • 12
  • 140
  • 224