I am looking in a vector similar to this
x <- c("P1D3,P3A7", 0, 0, "P1D3,P3A7", "P1D3, P2A3, P4D2", 0, "P1D3, P3A7, P2G60", "P1D3,P3A7")
I currently have it using grepl
xPres <- grepl("P",x, ignore.case = FALSE)
Currently if I did
View(xPres)
I would see a vector like this
(TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE)
However, I don't just want to look for anything containing a value other than 0 in it, I want to be able to check to see if a value in a vector or a part of the value in the vector matches some other value or part of a value in the same vector.
The ideal result would produce something like this
(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE)
The 5th value would change because it does not have any part that is matching, whereas everything else has some part of it that is matching some other value in the same vector, including the 7th value because a portion of it is matching some other value.
The only problem is that every value has "P1D3", because it is present in all of the samples. Is there a way to solve this problem?
Edit: If I created a new vector with
x <- c("P1D3,P3A7", 0, 0, "P1D3,P3A7", "P1D3, P2A3, P4D2", 0, "P1D3, P3A7, P2G60", "P1D3,P3A7", "P1D3, P2A3, P4D2")
the code should produce
(TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE)
It seems that finding multiple common substrings is the simplelest way to go, but I do not know the package to download or what to use.