An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090429/7b0646e4/attachment-0001.pl>
if condition doesn't evaluate to True/False
7 messages · Moumita Das, Matthias Burger, PIKAL Petr +1 more
see
?is.null
e.g.
if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
{
your code
}
Moumita Das wrote:
Hi friends, Please help me with this bug. *Bug in my code:* In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where clause.every sub group has a where condition linked with it. Database1 Where clause was not found for a particular subgroup, sub_grp_whr_cls_data[sbgrp_no,1] value was NULL So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to TRUE ,but it evaluated to NA So the if block where I used the the condition threw error If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) i.e if(NA) Error:-- Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" || sub_grp_whr_cls_data[sbgrp_no, : missing value where TRUE/FALSE needed Comments:-- but when there ?s no where clause value the condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should automatically evaluate to * TRUE* Database2 Where clause was found for a particular subgroup The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is If (FALSE) ,control goes to the else part. This is exactly what is expected of the program. *QUERY:-- **If the condition evaluates to FALSE when a where condition is available why doesn?t it evaluate to TRUE when a where condition available is NULL or no where condition is available.* Here I have taken the example of two databases where I tried to get the where clause for subgroup 1.In case of Database1 it was not available in case of Databse2 it was available.But the problem may appear for the same database also, when where clause is available for say one subgroup and not for the other. ------------------------------------------------------------------------
______________________________________________ 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.
Matthias Burger Project Manager/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-0 fax:+49-30-24345-555 http://www.epigenomics.com matthias.burger at epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)
Hi you put your problem in absolutely messy state r-help-bounces at r-project.org napsal dne 29.04.2009 16:16:55:
Hi friends, Please help me with this bug. *Bug in my code:* In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where clause.every sub group has a where condition linked with it. Database1 Where clause was not found for a particular subgroup, sub_grp_whr_cls_data[sbgrp_no,1] value was NULL So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to TRUE ,but it evaluated to NA
Are you sure that sub_grp_whr_cls_data[sbgrp_no,1] was either "NULL" or "" I suspect that it is NA you can get three results with logical values
x<-c(1,"NULL", NA, "", 1) x=="NULL"|x==""
[1] FALSE TRUE NA TRUE FALSE So if the value is "NULL" or "" you will get TRUE, if it is anything else you will get FALSE but if it is NA you will get NA. Actually if the value is NA you do not know if it should be "NULL", "" or anything else therefore result is NA Regards Petr
So the if block where I used the the condition threw error If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) i.e if(NA) Error:-- Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" || sub_grp_whr_cls_data[sbgrp_no, : missing value where TRUE/FALSE needed Comments:-- but when there ?s no where clause value the condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should automatically evaluate to
*
TRUE* Database2 Where clause was found for a particular subgroup The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is If (FALSE) ,control goes to the else part. This is exactly what is expected of the program. *QUERY:-- **If the condition evaluates to FALSE when a where condition
is
available why doesn?t it evaluate to TRUE when a where condition
available
is NULL or no where condition is available.* Here I have taken the example of two databases where I tried to get the where clause for subgroup 1.In case of Database1 it was not available in case of Databse2 it was available.But the problem may appear for the
same
database also, when where clause is available for say one subgroup and
not
for the other. -- Thanks Moumita [[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.
Hi r-help-bounces at r-project.org napsal dne 29.04.2009 17:05:01:
see
?is.null
e.g.
if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
{
your code
}
It probably will not work as sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" implicates that there is character value "NULL". I am not sure if you can get NULL as a part of some object. I tried and failed. See what you get x<- c(1,2,3, NULL) Regards Petr
Moumita Das wrote:
Hi friends, Please help me with this bug. *Bug in my code:* In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where clause.every sub group has a where condition linked with it. Database1 Where clause was not found for a particular subgroup, sub_grp_whr_cls_data[sbgrp_no,1] value was NULL So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to TRUE ,but it evaluated to NA So the if block where I used the the condition threw error If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) i.e if(NA) Error:-- Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" || sub_grp_whr_cls_data[sbgrp_no, : missing value where TRUE/FALSE needed Comments:-- but when there ?s no where clause value the condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should automatically evaluate
to *
TRUE* Database2 Where clause was found for a particular subgroup The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is If (FALSE) ,control goes to the else part. This is exactly what is expected of the program. *QUERY:-- **If the condition evaluates to FALSE when a where
condition is
available why doesn?t it evaluate to TRUE when a where condition
available
is NULL or no where condition is available.* Here I have taken the example of two databases where I tried to get
the
where clause for subgroup 1.In case of Database1 it was not available
in
case of Databse2 it was available.But the problem may appear for the
same
database also, when where clause is available for say one subgroup and
not
for the other.
------------------------------------------------------------------------
______________________________________________ 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.
-- Matthias Burger Project Manager/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-0 fax:+49-30-24345-555 http://www.epigenomics.com matthias.burger at epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)
______________________________________________ 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.
test <- list(NULL) Bert Gunter Nonclinical Biostatistics 467-7374
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Petr PIKAL Sent: Wednesday, April 29, 2009 8:21 AM To: ml-r-help at epigenomics.com Cc: r-help at stat.math.ethz.ch; Moumita Das Subject: Re: [R] if condition doesn't evaluate to True/False Hi r-help-bounces at r-project.org napsal dne 29.04.2009 17:05:01:
see
?is.null
e.g.
if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
{
your code
}
It probably will not work as sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" implicates that there is character value "NULL". I am not sure if you can get NULL as a part of some object. I tried and failed. See what you get x<- c(1,2,3, NULL) Regards Petr
Moumita Das wrote:
Hi friends, Please help me with this bug. *Bug in my code:* In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store
the where
clause.every sub group has a where condition linked with it. Database1 Where clause was not found for a particular subgroup, sub_grp_whr_cls_data[sbgrp_no,1] value was NULL So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to
TRUE ,but it
evaluated to NA So the if block where I used the the condition threw error If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) i.e if(NA) Error:-- Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" || sub_grp_whr_cls_data[sbgrp_no, : missing value where TRUE/FALSE needed Comments:-- but when there 's no where clause value the condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should
automatically evaluate to *
TRUE* Database2 Where clause was found for a particular subgroup The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is If (FALSE) ,control goes to the else part. This is exactly what is expected of the program. *QUERY:-- **If the condition evaluates to FALSE when a where
condition is
available why doesn't it evaluate to TRUE when a where condition
available
is NULL or no where condition is available.* Here I have taken the example of two databases where I
tried to get the
where clause for subgroup 1.In case of Database1 it was
not available in
case of Databse2 it was available.But the problem may
appear for the same
database also, when where clause is available for say one
subgroup and not
for the other.
-------------------------------------------------------------- ----------
______________________________________________ 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. -- Matthias Burger Project Manager/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-0 fax:+49-30-24345-555 http://www.epigenomics.com matthias.burger at epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender) ______________________________________________ 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. ______________________________________________ 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.
Petr PIKAL wrote:
Hi r-help-bounces at r-project.org napsal dne 29.04.2009 17:05:01:
see
?is.null
e.g.
if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
{
your code
}
It probably will not work as sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" implicates that there is character value "NULL". I am not sure if you can get NULL as a part of some object. I tried and failed. See what you get x<- c(1,2,3, NULL) Regards Petr
thanks for pointing this out clearly, I had thought only about making the comparison return a logical for use in the expression. On hindsight it seems implausible to ever get NULL in the matrix/data frame. (DONT USE playing around I found the following abuse to work m <- as.data.frame(diag(3)) m[[3]][3] <- list(NULL) is.null(m[3,3][[1]]) [1] TRUE ) Regards, Matthias
Moumita Das wrote:
Hi friends, Please help me with this bug. *Bug in my code:* In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store the where clause.every sub group has a where condition linked with it. Database1 Where clause was not found for a particular subgroup, sub_grp_whr_cls_data[sbgrp_no,1] value was NULL So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to TRUE ,but it evaluated to NA So the if block where I used the the condition threw error If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) i.e if(NA) Error:-- Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" || sub_grp_whr_cls_data[sbgrp_no, : missing value where TRUE/FALSE needed Comments:-- but when there ?s no where clause value the condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should automatically evaluate
to *
TRUE* Database2 Where clause was found for a particular subgroup The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is If (FALSE) ,control goes to the else part. This is exactly what is expected of the program. *QUERY:-- **If the condition evaluates to FALSE when a where
condition is
available why doesn?t it evaluate to TRUE when a where condition
available
is NULL or no where condition is available.* Here I have taken the example of two databases where I tried to get
the
where clause for subgroup 1.In case of Database1 it was not available
in
case of Databse2 it was available.But the problem may appear for the
same
database also, when where clause is available for say one subgroup and
not
for the other.
------------------------------------------------------------------------
______________________________________________ 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. -- Matthias Burger Project Manager/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-0 fax:+49-30-24345-555 http://www.epigenomics.com matthias.burger at epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender) ______________________________________________ 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. ______________________________________________ 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.
Matthias Burger Project Manager/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-0 fax:+49-30-24345-555 http://www.epigenomics.com matthias.burger at epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)
OK test <- list( NULL, NULL, NULL) gives you list with three null values. But you can not subscript it like test[[1,1] what original poster did and you can not produce data frame with multiple NULL values test <- data.frame(NULL, NULL, NULL)
test
data frame with 0 columns and 0 rows
str(test)
'data.frame': 0 obs. of 0 variables and test it with is.null
is.null(test)
[1] FALSE regards Petr Bert Gunter <gunter.berton at gene.com> napsal dne 29.04.2009 18:34:00:
test <- list(NULL) Bert Gunter Nonclinical Biostatistics 467-7374
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Petr PIKAL Sent: Wednesday, April 29, 2009 8:21 AM To: ml-r-help at epigenomics.com Cc: r-help at stat.math.ethz.ch; Moumita Das Subject: Re: [R] if condition doesn't evaluate to True/False Hi r-help-bounces at r-project.org napsal dne 29.04.2009 17:05:01:
see
?is.null
e.g.
if( is.null(sub_grp_whr_cls_data[sbgrp_no, 1]) )
{
your code
}
It probably will not work as sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" implicates that there is character value "NULL". I am not sure if you can get NULL as a part of some object. I tried and failed. See what you get x<- c(1,2,3, NULL) Regards Petr
Moumita Das wrote:
Hi friends, Please help me with this bug. *Bug in my code:* In this variable sub_grp_whr_cls_data[sbgrp_no,1] I store
the where
clause.every sub group has a where condition linked with it. Database1 Where clause was not found for a particular subgroup, sub_grp_whr_cls_data[sbgrp_no,1] value was NULL So the condition (*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) should evaluate to
TRUE ,but it
evaluated to NA So the if block where I used the the condition threw error If(*sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" || sub_grp_whr_cls_data[sbgrp_no,1]==""*) i.e if(NA) Error:-- Error in if (sub_grp_whr_cls_data[sbgrp_no, 1] == "NULL" || sub_grp_whr_cls_data[sbgrp_no, : missing value where TRUE/FALSE needed Comments:-- but when there 's no where clause value the condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") should
automatically evaluate to *
TRUE* Database2 Where clause was found for a particular subgroup The condition (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") evaluated to FALSE So if (sub_grp_whr_cls_data[sbgrp_no,1]=="NULL" ||sub_grp_whr_cls_data[sbgrp_no,1]=="") is If (FALSE) ,control goes to the else part. This is exactly what is expected of the program. *QUERY:-- **If the condition evaluates to FALSE when a where
condition is
available why doesn't it evaluate to TRUE when a where condition
available
is NULL or no where condition is available.* Here I have taken the example of two databases where I
tried to get the
where clause for subgroup 1.In case of Database1 it was
not available in
case of Databse2 it was available.But the problem may
appear for the same
database also, when where clause is available for say one
subgroup and not
for the other.
-------------------------------------------------------------- ----------
______________________________________________ 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. -- Matthias Burger Project Manager/ Biostatistician Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany phone:+49-30-24345-0 fax:+49-30-24345-555 http://www.epigenomics.com matthias.burger at epigenomics.com -- Epigenomics AG Berlin Amtsgericht Charlottenburg HRB 75861 Vorstand: Geert Nygaard (CEO/Vorsitzender) Oliver Schacht PhD (CFO) Aufsichtsrat: Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender) ______________________________________________ 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. ______________________________________________ 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.