Remove strings found in vector 1, from vector 2
问题 I have these two vectors: sample1 <- c(".aaa", ".aarp", ".abb", ".abbott", ".abogado") sample2 <- c("try1.aarp", "www.tryagain.aaa", "255.255.255.255", "onemoretry.abb.abogado") I am trying to remove sample1 strings that are found in sample2. The closest I got is by iterating using sapply , which gave me this: sapply(sample1, function(i)gsub(i, "", sample2)) .aaa .aarp .abb .abbott .abogado [1,] "try1.aarp" "try1" "try1.aarp" "try1.aarp" "try1.aarp" [2,] "www.tryagain" "www.tryagain.aaa" "www