Skip to content
Prev 281121 / 398503 Next

Merging vectors

Does the following do what you want?  You didn't
describe the rule and the example output was truncated:

EV <- c(
   9,16,19,21,67,71,82,87,110,112,141,156,201,211,248,264,272,298,331,
   341,347,361,373,468,490,493,504,508,806,830,833,883,885,897,953,955)

SV <- c(
   3,21,28,33,229,379,396,532,535,541,630,634,643,645,647,654,656,677,680,
   685,687,718,727,735,738,746,748,751,766,768,903,926,936,995,999)

f1 <- function(EV, SV) {
   names(EV) <- rep("EV", length(EV))
   SV <- SV[SV >= min(EV)]
   names(SV) <- rep("SV", length(SV))
   z <- sort(c(SV, EV))
   nms <- names(z)
   unname(z[c(TRUE, nms[-1] != nms[-length(z)])])
}

f1(EV,SV)
# gives [1]   9  21  21  28  67 229 248 379 468 532 806 903 953 995
# wanted 9, 21, 21, 28, 67, 229, 248, 379..

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com