简体   繁体   中英

How to count nul values in R

I want to inspect a file before processing it in R.

It is possible, that my input file is broken and contains nul values, due to a software crash. So I want my script to have a look at the data before continuing the process.

If I do a read.csv(..., skipNul = TRUE) , the nuls were skipped and the script doesn't stop. But this is bad, because I don't see the lack of data.

If I do a read.csv(..., skipNul = FALSE) ,the nuls were skipped anyway, and I just get a warning message.

I want to count the nuls inside the file. But how can I do this?

I tried to change the encoding, but nuls are never shown when printing the dataframe.

I think, I found a solution here: Removing nul characters

I can read the raw data by DF <- readBin("Example.log", raw(), file.info("Example.log")$size) .

The resulting vector contains all 1 byte char values. I just had to filter for the nuls and print the length: length(DF[DF == 0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM