问题
I have a csv with millions of cases that look like this:
Case_1,11,17481,172,4436,8,4436
Case_2,11,1221,680,55200,1776,55200
Case_3,16,6647,6449,579967,1,579967
Case_4,22,0,0,0,0,0
In this case, Case_4
is missing data, since it has a bunch of zeros in it (there are hundreds of these in the file). I'm very new to R, and I was wondering if there is an efficient way of deleting these kinds of missing data from the file? Thanks.
回答1:
Use the na.strings
argument when reading in your file.
df <- read.csv("filename.csv", na.strings="0")
回答2:
if you want to replace all your zeros with missing values than.
x = data.frame(dataset)
x[x==0] = NA
Where dataset is the variable where you have saved the csv file
回答3:
To delete the rows which have 0 entries (as desired by OP):
ddf[ddf==0]=NA
ddf = ddf[complete.cases(ddf),]
来源:https://stackoverflow.com/questions/26957742/zeros-as-missing-cases-in-r