[R] Logical operations or selecting data from data.frames

Johan Sandblom johan.sandblom at ki.se
Tue Jan 9 18:56:16 CET 2007


Is the solution this simple?

sdata$VaR < sdata$DdtdAbs & sdata$DdtdDuration >= 1

Regards, Johan

2007/1/9, Benjamin Dickgiesser <dickgiesser at gmail.com>:
> I suppose this doesn't work for the same reason as
> sdata$VaR < sdata$DdtdAbs && sdata$DdtdDuration >= 1
>
> does only return  FALSE and not a vector of TRUE and FALSE as
>
> sdata$VaR < sdata$DdtdAbs
>
> would return.
>
> Is there a ways around this?
> Benjamin
>
> On 1/9/07, Benjamin Dickgiesser <dickgiesser at gmail.com> wrote:
> > Hi all,
> >
> > why doesn't something like this does not work?
> >
> > speedy <-
> >         (sdata$VaR < sdata$DdtdAbs) && sdata$DdtdDuration >= qpois(pct,lambda) &&
> >         sdata$Ddtd > MinDD
> >
> > or sdata$Ddtd[sdata$Ddtd > 0 && sdata$VaR < sdata$DdtdAbs]
> >
> > sdata looks like this:
> >
> >            dataId       date  value Ddtd VaR DdtdAbs DdtdDuration
> > 18948  79637 2004-07-27 10085.10           NA         NA    0.00            0
> > 18949  79638 2004-07-28 10117.10           NA         NA    0.00            0
> > 18950  79639 2004-07-29 10129.20           NA         NA    0.00            0
> > 18951  79640 2004-07-30 10139.70           NA         NA    0.00            0
> > 18952  79641 2004-08-02 10179.20           NA         NA    0.00            0
> > 18953  79642 2004-08-03 10120.20  0.579613329 336.060090   59.00            1
> > 18954  79643 2004-08-04 10126.50           NA         NA    0.00            0
> > 18955  79644 2004-08-05  9963.03  1.614279366 334.306978  163.47            1
> > 18956  79645 2004-08-06  9815.33  3.072828717 386.173057  311.17            2
> > 18957  79646 2004-08-09  9814.66  3.079445020 420.167049  311.84            3
> > 18958  79647 2004-08-10  9944.67           NA         NA    0.00            0
> > 18959  79648 2004-08-11  9938.32  0.063853300 328.315992    6.35            1
> > 18960  79649 2004-08-12  9814.59  1.308037371 379.182568  130.08            2
> >
> > I am trying to select rows from the data.frame which have Ddtd > x,
> > VaR < DdtdAbs and DdtdDuration > z.
> >
> > Thank you,
> > Benjamin
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
Johan Sandblom  N8, MRC, Karolinska sjh
t +46851776108  17176 Stockholm
m +46735521477  Sweden
"What is wanted is not the will to believe, but the
will to find out, which is the exact opposite"
- Bertrand Russell



More information about the R-help mailing list