I have a dataset with 20,000 rows that in its purest form looks like this:
v1 v2
1 Case 1 (A v. B) A v. B
2 Case 2 (A v. C) A v. B
3 Case 2 (A v. C) C v. B
4 Case 4 (X v. Z) X v. Z
5 Case 5 (B v. A) A v. B
6 Case 6 (X v. A) X v. A
7 Case 6 (X v. A) A v. X
...
...except there are n-many variations of v1, v2 (actually around ~150, but still too many to list).
I want to return a third column v3 containing a logical indicator of whether any substring of v1 matches the string in v2.
v1 v2 v3
1 Case 1 (A v. B) A v. B TRUE
2 Case 2 (A v. C) A v. B FALSE
3 Case 2 (A v. C) C v. B FALSE
4 Case 4 (X v. Z) X v. Z TRUE
5 Case 5 (B v. A) A v. B FALSE
6 Case 6 (X v. A) X v. A TRUE
7 Case 6 (X v. A) A v. X FALSE
I've been playing around with something like this, which I think is on the right track:
library(stringr)
x$v3 <- with(x, str_detect(v1, v2))
I'd be very grateful if someone could point me in the right direction to a solution/workaround.
MWE shows that my str_detect() technique does not work:
x <- structure(list(v1 = c("Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation",
"Application of the International Convention on the Elimination of All Forms of Racial Discrimination Georgia v Russian Federation"
), v2 = c("Georgia v Russian Federation", " Ethiopia v South Africa Liberia v South Africa",
" Cameroon v United Kingdom", " New Zealand v France", " Australia v France",
" Nicaragua v United States of America", " Nicaragua v Honduras",
" Nauru v Anustralia", " Nnew Zealand v France", " Islamic Republic of Iran v United States of America",
" Bosnia and Herzegovina v Serbia and Montenegro", " Spain v Cananda",
" Libyan Arab Jamahiriya v United States of America", " Libyan Arab Jamahiriya v United Kingdom",
" Democratic Republic of the Congo v Burundi", " Germany v United States of America",
" Democratic Republic of the Congo v Belgium", " Liechtenstein v Germany",
" Democratic Republic of the Congo v Ugandan", " Democratic Republic of the Congo v Rwandan",
" Nicaragua v Colombia", " Djibouti v France", " Georgia v Russian Federation",
" Croatia v Serbia", " Mexico v United States of American", " Democratic Republic of the Congo v Rwanda",
" Spain v Canada", " Australia v France", " New Zealand v France",
" New Zealand v France")), .Names = c("v1", "v2"
), row.names = c(NA, 30L), class = "data.frame")