简体   繁体   English

如何处理R中的NaN?

[英]How to deal with NaN in R?

I have two binary files with the same dimensions(corr and rmse ).I want to do this: replace all pixels in rmse by NA whenevr corr is NA. 我有两个具有相同尺寸的二进制文件(corr和rmse)。我想这样做:用NA替换rmse中的所有像素为whenevr corr为NA。

file1: 文件1:

conne <- file("D:\\omplete.bin","rb")
corr<- readBin(conne, numeric(), size=4,  n=1440*720, signed=TRUE)

file2: 文件2:

rms <- file("D:\\hgmplete.bin","rb")
rmse<- readBin(rms, numeric(), size=4,  n=1440*720, signed=TRUE)

I did this: 我这样做了:

rmse[corr==NA]=NA 

did not do anything, so I tried this: 什么都没做,所以我试过这个:

rmse[corr==NaN]=NA 

did not do anything either! 什么都没做! Can anybody help me on this. 任何人都可以帮我这个。

Head of the file corr: 文件负责人:

> corr
[1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 

You need to use the logical test is.nan() . 您需要使用逻辑测试is.nan() In this case: 在这种情况下:

rmse[is.nan(corr)]=NA

should do the trick 应该做的伎俩

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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