I have several vectors, like these ones:
str <- c("AT/FBA/1/12/360/26/SF/96", "AT/RLMW/1/12/360/44/SF/122", "AT/ACR/1/12/362/66/SF/175", "AT/AA/1/12/363/72/SF/281", "AT/BB/1/12/364/90/SF/310", "AT/ANT/1/123/364/92/SF/338")
N.B. that each argument between '/' may change in length (amount of characters).
I want to extract the 5th and 6th arguments delimited by the '/'.
for example in this case:
"360/26", "360/44", "362/66", "363/72", "364/90", "364/92"
I checked at these answers from similar questions: Extract text after a symbol in R - Extracting part of string by position in R -
I tried to use:
sub("^([^/]+/){4}([^/]+).*", "\\2", str)
but it gives me only the 5th argument, as follow:
[1] "360" "360" "362" "363" "364" "364" "364" "365" "365" "366" "365" "002" "002" "002" "002" "003"
[17] "003" "003" "004" "004" "004" "005"
then I tried
scan(text=str, sep="/", what="", quiet=TRUE)[c(5:6)]
but it gives me just the two arguments without the delimiter '/'.