It would help if you provided a reproducible example. Since you didn't, I'll try to make one. Hopefully, this will be worthwhile.
write.csv(read.table(text="A 1 2 3
B 2 3 4
C 3 4 5
D 4 5 6
E 5 q 7
F 6 7 8
G 7 8 9", header=F, stringsAsFactors=F), file="file.csv", row.names=F)
This file should open with numeric variables (other than the first column), but the third column is screwed up somewhere:
my.data <- read.csv("file.csv", stringsAsFactors=F, header=T)
str(my.data)
# 'data.frame': 7 obs. of 4 variables:
# $ V1: chr "A" "B" "C" "D" ...
# $ V2: int 1 2 3 4 5 6 7
# $ V3: chr "2" "3" "4" "5" ...
# $ V4: int 3 4 5 6 7 8 9
One thing you can try is to read in the file one row at a time, and see when the class of the variable in question switches from numeric:
for(i in 1:7){
row <- read.csv("file.csv", stringsAsFactors=F, header=T, skip=i-1, nrows=1)
if(is.character(row[1,3])){ break() }
}
i # [1] 5
row[1,3] # [1] "q"
Having discovered the culprit (or at least the first one), you could open the file in Excel, or something like EditPad, and navigate to the bad element and fix it. (Be sure to do this to a copy of the file; keep the original—warts and all—for a permanent record.)
Edit:
If you already have a vector with NA
s, you can find out where they are with:
which(is.na(as.numeric(my.data[,3])))
# [1] 5
# Warning message:
# In which(is.na(as.numeric(my.data[, 3]))) : NAs introduced by coercion
Or jump straight to inspecting the elements with:
my.data[which(is.na(as.numeric(my.data[,3]))),3]
# [1] "q"
# Warning message:
# In which(is.na(as.numeric(my.data[, 3]))) : NAs introduced by coercion