i have vector composed these strings:
10i/v/f/r, 16e, 20r/m/t/i, 24i, 32i, 33f/i/v, 36i/l/v,45r, 46i/l/v, 48m/v, 53l, 54l/m/v, 60e, 63p, 71v/t/i,73c/s/t/a, 82a/f/i/s/t/m/l/c, 84a/c/v,85v, 88d/t/s, 89m/v/q/t, 90m
and have that:
10f, 20m, 33f, 82a, 89q, 93k
i verify if each string of second vector exists in first. in example, true first five, because each number, letter associated present. receive answer numbers of strings match, in case, 5.
we can transform search strings regexes , match each 1 against target vector. since want number of search strings matched, can count how many search strings had @ least 1 match in target vector.
sum(lengths(lapply(sub('^([0-9]+)([a-za-z])$','^\\1.*\\2',b),grep,a))>0l); ## [1] 5
data
a <- c('10i/v/f/r','16e','20r/m/t/i','24i','32i','33f/i/v','36i/l/v,45r','46i/l/v','48m/v', '53l','54l/m/v','60e','63p','71v/t/i,73c/s/t/a','82a/f/i/s/t/m/l/c','84a/c/v,85v','88d/t/s', '89m/v/q/t','90m'); b <- c('10f','20m','33f','82a','89q','93k');
Comments
Post a Comment