[R] Select only cases with negative values

Michael Just mgjust at gmail.com
Sat Oct 18 23:22:24 CEST 2008


Johannes,
Thanks for the response. However, ...
> dat.neg <- dat[dat$d < 0, ]
Error in dat[dat$d < 0, ] : incorrect number of dimensions
In addition: Warning message:
$ operator is deprecated for atomic vectors, returning NULL in: dat$d

Any other ideas?
Thanks,
Michael


On Sat, Oct 18, 2008 at 5:18 PM, Johannes Hüsing <johannes at huesing.name> wrote:
>
> Am 18.10.2008 um 23:03 schrieb Michael Just:
>
>> Hello,
>> I was wondering if there was a way to only select cases my from data
>> frame that contained a negative value?
>>
>>> c<-c(1,2,3,4,5,6,7,8,9,10)
>>> d<- c(-1,2,-3,-4,5,6,-7,8,-9,10)
>>> f <- cbind(c,d)
>>> dat <-data.frame(f)
>>> dat.lm <-lm(c~d)
>>
>> If I wanted to only use the rows that had a negative value in column d
>> for my regression, how could I make that selection?
>>
>>
>
> untested:
> dat[dat$d < 0, ]
>
>



More information about the R-help mailing list