This is better explained by example:
A <- data.frame(force = sort(runif(10, 0, 1)), condition =
sort(sample(0:100, 10)))
B <- data.frame(counterforce = sort(runif(15, 0, 1), decreasing=T),
condition = sort(sample(0:100, 15)))
So we have:
A
force condition
1 0.03515542 1
2 0.13267882 13
3 0.26155689 24
4 0.37453142 38
5 0.39360520 45 <--- trim everything after this
6 0.43924737 48
7 0.47669800 50
8 0.57044795 51
9 0.81177499 61
10 0.98860450 94
B
counterforce condition
1 0.965769548 2
2 0.965266255 5
3 0.846941244 7
4 0.818013029 11
5 0.813139978 22
6 0.730599939 34
7 0.715985436 39
8 0.658073895 40
9 0.421264948 42 <--- trim everything after this
10 0.373774505 52
11 0.242191461 62
12 0.090584590 63
13 0.070020635 68
14 0.067366062 83
15 0.001585313 84
I need to trim away rows after No. 5, from A, trim away rows after No.
9, from B.
Because
A[5, condition] > max(B[1:9, condition] && A[5, force] > B[9+1, counterforce]
In a general way, I am looking for x and y, where:
A[x, condition] > max(B[1:y, condition] && A[x, force] > B[y+1, counterforce]
and I will select A[1:x,] and B[1:y,], or trim away the rest, because
they are irrelevent for the calculation onwards.
This is easy to do it in C, and I actually have done it in C-like R
script, by looping through all rows of A, and breaking from the loop
when finding the matching trim-point in B. But I am learning R, so
what is the native way to do it in R?
-------------------------------------------------
VFEmail.net - http://www.vfemail.net
$14.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!
______________________________________________
R-help@r-project.org 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.