> S=c("World_is_beautiful", "one_two_three_four","My_book")
> I need to extract the last but one element of the strings. So, my
> output should look like:
> Ans=c("is","three","My")
> gsub() can do this...but wondering how do I give the regular
expression....
sapply(strsplit(S, "_"), function(x) x[length(x)-1])
You could use regular expressions, but I think it would only be
complicating things.
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}
______________________________________________
R-help@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide
http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Regards,
Richie.
Mathematical Sciences Unit
HSL