I have data in that string is like f <- "./DAYA-1178/10TH FEB.xlsx". I would like to extract only DAYA-1178
what I have tried is
f1 <- gsub(".*./","", f)
But it is giving last result of my file "10TH FEB.xlsx"
Appreciate any lead.
It seems you are dealing with files. You need the basename of the directory:
basename(dirname(f))
[1] "DAYA-1178"
or you could do:
sub(".*/","",dirname(f))
[1] "DAYA-1178"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With