[R] how to do this trimming/selecting in canonical R?
gildororonar at mail-on.us
gildororonar at mail-on.us
Sun Sep 15 04:21:03 CEST 2013
Quoting "Gabor Grothendieck" <ggrothendieck at gmail.com>:
> Try this:
>
> library(sqldf)
Thank you for introducing me to SQLDF package! I wasn't aware I could
use SQL in R!
Right now Arun sent me (forgetting to cc the list) a solution using
apply/sapply, which inspired me of my own version:
> x <- which(sapply(seq_len(nrow(A)), function (x)
{ A[x, "force"] > B[sum(B[,"condition"] < A[x, "condition"])+1,
"counterforce"] }
))[1]
> y <- sum(B[,"condition"]<A[x,"condition"])
> c(x, y)
[1] 5 9
I am guessing this is already as good as can be.
--
To use the same test data as I have:
A <- read.table(text = "force condition
0.03515542 1 0.13267882 13
0.26155689 24
0.37453142 38
0.39360520 45
0.43924737 48
0.47669800 50
0.57044795 51
0.81177499 61
0.98860450 94", header=T)
B <- read.table(text = "counterforce condition
0.965769548 2 0.965266255 5
0.846941244 7
0.818013029 11
0.813139978 22
0.730599939 34
0.715985436 39
0.658073895 40
0.421264948 42
0.373774505 52
0.242191461 62
0.090584590 63
0.070020635 68
0.067366062 83
0.001585313 84", header=T)
-------------------------------------------------
VFEmail.net - http://www.vfemail.net
$14.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!
More information about the R-help
mailing list