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 causesissues Also, putting -0.01 in parentheses didn't help. Thanks in advance -- b
x <- rnorm(100) x[x < -1] x[x<(-1)] # both work for me! x[x<-1] # as you note gives problems. At 12:03 PM 10/13/2003 -0700, 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 >With best wishes and kind regards I am Sincerely, Corey A. Moffet, Ph.D. Support Scientist University of Idaho Northwest Watershed Research Center 800 Park Blvd, Plaza IV, Suite 105 Boise, ID 83712-7716 Voice: (208) 422-0718 FAX: (208) 334-1502
Add a spaces! hist(sp$p[sp$r > 0.01]) hist(sp$p[sp$r < -0.01]) compare with hist(sp$p[sp$r <- 0.01]) which is what you tried. Cheers. Henrik Bengtsson Lund University> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Brian J. Haag > Sent: den 13 oktober 2003 21:03 > To: r-help at stat.math.ethz.ch > Subject: [R] conditional less than > > > 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/mailma> n/listinfo/r-help > >
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
>
>
Thanks to all for the help ... I rather immediately realized (*blush*) that I had run it incorrectly the first time and blown up my series, so of course nothing else worked either. Parentheses is all that was needed. Sorry for the wasted bandwidth. b