[R] Error Missing values where true/false needed

PIKAL Petr petr.pikal at precheza.cz
Wed Nov 26 08:41:14 CET 2014


Huh

and what is the result of e.g.

data$Rain[indicNAs[1]]

I bet that you will see

[1] NA

and your if question askes if (NA eqals 60) which results in NA and "if" is telling you that it expects TRUE or FALSE but not NA.

I do not see how much clearer the error message shall be.

Cheers
Petr

> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of
> Frederic Ntirenganya
> Sent: Wednesday, November 26, 2014 7:27 AM
> To: Michael Dewey
> Cc: r-help at r-project.org
> Subject: Re: [R] Error Missing values where true/false needed
>
> Hi PIKAL,
>
> The error seems to be starnge to me because i access the indices of
> NAs.
> Indices can't be non-applicable.
> 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
> 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>
> 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.
> >
> >
> >
> > 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)
> >>    ind_nonleap = c() # NAs due to non leap years
> >>    ind_nonrecord = c() # NAs due to non recording values
> >>    for (i_NA in indicNAs ){
> >>      if(data$Rain[i_NA] == 60){
> >>        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
> >> https://sites.google.com/a/aims.ac.za/fredo/
> >>
> >>         [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide 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
> >> Version: 2015.0.5577 / Virus Database: 4223/8627 - Release Date:
> >> 11/25/14
> >>
> >>
> >>
> > --
> > Michael
> > http://www.dewey.myzen.co.uk
> >
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.


More information about the R-help mailing list