[R] Selecting values based on two criteria

Morway, Eric emorway at usgs.gov
Fri Dec 26 22:16:32 CET 2014


I'm in need of help selecting from d2 those values that come after a value
in d1.  For example, d2[1] is both greater than d1[1] and is the value that
is closest to d2[1].  Similarly, d2[2] is both greater than d1[2] and is
the next "highest" number in d2.  Every value in d1 has a corresponding
value in d2 based on this criteria, however, many of the values in d2 will
be discarded.  The final result I'm looking for is a subset of d2 as given
in d3.  Notice for example that 140569 is discarded and not contained in
d3.  This small example is of course a much smaller example of a much
larger problem.  Example R script of how to whittle down d2 to look like d3
based on the criteria above

d1 <- c(135631,136950,137952,138787,139623,142231,143067,144762,
        145601,146441)

d2 <- c(135882,136954,137956,138792,139630,140569,141398,142237,
        143078,143907,144771,145611,146446,147285,148128)

d3 <- c(135882,136954,137956,138792,139630,142237,143078,144771,
        145611,146446)

	[[alternative HTML version deleted]]



More information about the R-help mailing list