[R] Error Missing values where true/false needed

Michael Dewey info at aghmed.fsnet.co.uk
Wed Nov 26 14:38:53 CET 2014


Comments in-line below

On 26/11/2014 06:27, Frederic Ntirenganya wrote:
> Hi PIKAL,
>
Actually I am Michael, Petr is one of the other respondents.

> The error seems to be starnge to me because i access the indices of NAs.
> Indices can't be non-applicable.

But you are not testing the indexes, see below

> This is the output of indecs having the NA in my dataset. my dataset is
> very big that's why I did not provide it.
>
>  > indicNAs <- which(data$Rain %in% NA)
>  > indicNAs
>   [1]   426   792  1158  1890  2256  2622  3354  3720  4086  4818  5184
> 5550  6282  6648  7014  7746  8112
> [18]  8478  9210  9576  9942 10674 11040 11406 12138 12504 12870 13602
> 13968 14334 15066 15432 15798 16530
> [35] 16896 17262 17994 18360 18726 19458 19824 20190
>
> Regards,
> Frederic.
>
> Frederic Ntirenganya
> Maseno University,
> African Maths Initiative,
> Kenya.
> Mobile:(+254)718492836
> Email: fredo at aims.ac.za <mailto:fredo at aims.ac.za>
> https://sites.google.com/a/aims.ac.za/fredo/
>
> On Tue, Nov 25, 2014 at 3:51 PM, Michael Dewey <info at aghmed.fsnet.co.uk
> <mailto:info at aghmed.fsnet.co.uk>> wrote:
>
>     You do not tell us what you are trying to do but I think there is
>     something wrong in the logic of your thinking as on the one hand you
>     are selecting just precisely those elements of data$Rain which are
>     NA and then testing whether any of them equals 60.
>

My comments on your code are preceded ## to make them clear

>
>
>     On 25/11/2014 12:19, Frederic Ntirenganya wrote:
>
>         Dear All,
>
>         I am getting this error and don't know why it comes. can you
>         please help ?
>
>         Error in if (data$Rain[i_NA] == 60) { :
>             missing value where TRUE/FALSE needed
>
>         The loop is :
>
>         indicNAs <- which(data$Rain %in% NA)
## so at this point indicNAs is the indexes of all the NA
## values in dat$Rain
>             ind_nonleap = c() # NAs due to non leap years
>             ind_nonrecord = c() # NAs due to non recording values
>             for (i_NA in indicNAs ){ ## step through those indexes
>               if(data$Rain[i_NA] == 60){
## since i_NA is the index of a value of data$Rain which
## you know to be NA this evaluates to NA and if() complains
## I expect you really meant some other variable in data
## incidentally it is better not to call your data data
>                 ind_nonleap <- append(ind_nonleap,i_NA)
>               }
>               else {
>                 ind_nonrecord<-append(ind___nonrecord,i_NA)
>               }
>              #cat(ind_nonrecord)
>              #cat( ind_nonleap)
>             }
>             ind_nonleap
>
>         Regards,
>         Frederic.
>
>         Frederic Ntirenganya
>         Maseno University,
>         African Maths Initiative,
>         Kenya.
>         Mobile:(+254)718492836
>         Email: fredo at aims.ac.za <mailto:fredo at aims.ac.za>
>         https://sites.google.com/a/__aims.ac.za/fredo/
>         <https://sites.google.com/a/aims.ac.za/fredo/>
>
>                  [[alternative HTML version deleted]]
>
>         ________________________________________________
>         R-help at r-project.org <mailto:R-help at r-project.org> mailing list
>         https://stat.ethz.ch/mailman/__listinfo/r-help
>         <https://stat.ethz.ch/mailman/listinfo/r-help>
>         PLEASE do read the posting guide
>         http://www.R-project.org/__posting-guide.html
>         <http://www.R-project.org/posting-guide.html>
>         and provide commented, minimal, self-contained, reproducible code.
>
>
>         -----
>         No virus found in this message.
>         Checked by AVG - www.avg.com <http://www.avg.com>
>         Version: 2015.0.5577 / Virus Database: 4223/8627 - Release Date:
>         11/25/14
>
>
>
>     --
>     Michael
>     http://www.dewey.myzen.co.uk
>
>
> No virus found in this message.
> Checked by AVG - www.avg.com <http://www.avg.com>
> Version: 2015.0.5577 / Virus Database: 4223/8632 - Release Date: 11/25/14
>

-- 
Michael
http://www.dewey.myzen.co.uk



More information about the R-help mailing list