I have the following character vector in R called x
[1] "0_pt8a" "10_pt8a" "7_pt8a" "5_pt8a" "3_pt8a" "2_pt8a" "6_pt8a" "9_pt8a" "8_pt8a" "4_pt8a"
[11] "7_pt8b" "1_pt8b" "0_pt8b" "5_pt8b" "8_pt8b" "3_pt8b" "4_pt8b" "12_pt8b" "11_pt8b" "9_pt8b"
[21] "10_pt8b" "14_pt8c" "9_pt8c" "4_pt8c" "2_pt8c" "1_pt8c" "8_pt8c" "13_pt8c" "7_pt8c" "12_pt8c"
[31] "0_pt8c" "11_pt8c" "15_pt8c" "3_pt8c" "10_pt8c"
My goal is to output a list with only those with pattern than ends with _pt8a
desired output would be
"0_pt8a" "10_pt8a" "7_pt8a" "5_pt8a" "3_pt8a" "2_pt8a" "6_pt8a" "9_pt8a" "8_pt8a" "4_pt8a"
I tried multiple methods including
sapply(str_extract_all(x, "_pt8a"), paste, collapse=",")
substr(x, "^._pt8a")
Among other things from what I found on stackoverflow but none worked. I think this should be a simple thing but not sure why it is not working.