[R] Splitting the string at the last sub-string

Tuszynski, Jaroslaw W. JAROSLAW.W.TUSZYNSKI at saic.com
Thu Sep 15 15:01:57 CEST 2005


Hi,

I need to split a string into 2 strings, with the split point defined by the
last occurrence of some substring. I come up with some convoluted code to do
so:

str = "Chance favors the prepared mind"
sub = "e"
y = unlist(strsplit(str,sub))
z = cbind(paste(y[-length(y)], sub,  sep="", collapse = ""), y[length(y)]);

y
z
z[1]
z[2]

Is there a simpler way to do so? I think ~8 function calls to do such a
simple operation is an overkill.

Jarek 
====================================================\====                 
 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">  \ 
 Jaroslaw.W.Tuszynski at saic.com                    `    \




More information about the R-help mailing list