Skip to content

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

you put your problem in absolutely messy state

r-help-bounces at r-project.org napsal dne 29.04.2009 16:16:55:
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
[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
*
is
available
same
not
http://www.R-project.org/posting-guide.html
#
Hi

r-help-bounces at r-project.org napsal dne 29.04.2009 17:05:01:
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
to *
condition is
available
the
in
same
not
------------------------------------------------------------------------
http://www.R-project.org/posting-guide.html
http://www.R-project.org/posting-guide.html
#
test <- list(NULL)

Bert Gunter
Nonclinical Biostatistics
467-7374
#
Petr PIKAL wrote:
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

  
    
#
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)
data frame with 0 columns and 0 rows
'data.frame':   0 obs. of  0 variables

and test it with is.null
[1] FALSE

regards
Petr

Bert Gunter <gunter.berton at gene.com> napsal dne 29.04.2009 18:34:00: