[R] conditional less than

Spencer Graves spencer.graves at pdf.com
Mon Oct 13 21:30:30 CEST 2003


Putting -0.01 in parenthesis works for me.  Consider the following: 

 > DF <- data.frame(a=c(-2,2), b=3:4)
 > DF[DF$a<(-1),]
   a b
1 -2 3

However, if I first do it without parentheses, then I've changed DF 
before I attempt to subset it: 

 DF[DF$a<-0.01,]
[1] a b
<0 rows> (or 0-length row.names)
 > DF
     a b
1 0.01 3
2 0.01 4

This can create other problems, because now length(DF$a) == 1 (even 
though it printed as length 2): 

 > DF[DF$a<-1,]
     a b
1 0.01 3

hope this helps.  spencer graves

Brian J. Haag wrote:

>I'm sure this is a total noob question, but half an
>hour of searching bore no fruit: How do you select a
>subset of a vector by negative value?  If I try
>
>  
>
>>hist(sp$p[sp$r>0.01])   # all is well
>>hist(sp$p[sp$r<-0.01])  # this obviously causes
>>    
>>
>issues
>
>Also, putting -0.01 in parentheses didn't help.
>
>Thanks in advance --
>
>b
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>  
>




More information about the R-help mailing list