I have a text that looks like this:
txt <- "w.raw.median"
I want to extract the second word in between two periods (.
),
giving this output
> raw
But why this doesn't work
gsub(".*\\.", "", txt)
What's the right way to do it?
Try this:
gsub(".*\\.(.*)\\..*", "\\1", txt)
[1] "raw"
Also consider
strsplit(txt,'.',fixed=TRUE)[[1]][2]
for a (slightly) more readable version
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