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/
Error Missing values where true/false needed
7 messages · Frederic Ntirenganya, Boris Steipe, PIKAL Petr +1 more
Hi Error message seems to be clear
Error in if (data$Rain[i_NA] == 60) { :
missing value where TRUE/FALSE needed
data$Rain[i_NA] produces probably NA
x<-NA
if(x==60) print(1+1) else print("Errrorrr")
Error in if (x == 60) 1 + 1 : missing value where TRUE/FALSE needed
x<-10
if(x==60) print(1+1) else print("Errrorrr")
[1] "Errrorrr" Cheers Petr
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of Frederic Ntirenganya
Sent: Tuesday, November 25, 2014 1:20 PM
To: r-help at r-project.org
Subject: [R] Error Missing values where true/false needed
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.
________________________________ 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.
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
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
On Nov 26, 2014, at 1:27 AM, Frederic Ntirenganya <ntfredo at gmail.com> wrote:
The error seems to be starnge to me because i access the indices of NAs.
No you don't. You access the contents of the cell via an index for which you have previously determined that the contents is NA. Then you compare that contents with 60. The error is in the logic of these steps:
indicNAs <- which(data$Rain %in% NA) # indices for NA
for (i_NA in indicNAs ){ # i_NA is one of these indices
if(data$Rain[i_NA] == 60){ # data$Rain[i_NA] contains ... NA ! Never 60.
HTH, B.
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.
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