Skip to content
Prev 263023 / 398502 Next

how to subtract one string from another in R

Hi:

I think I misread your intentions the first time. Is this more in line
with what you want?

f <- function(s) {
     ssp <- unlist(strsplit(string, ""))
     n <- length(ssp)
     splits <- grep(' ', ssp)
     sapply(splits, function(x) paste(ssp[-(1:x)], collapse = ""))
   }
[1] "DEFG HIJKLM NOPQ RSTUV WXY" "HIJKLM NOPQ RSTUV WXY"
[3] "NOPQ RSTUV WXY"             "RSTUV WXY"
[5] "WXY"

The function returns a vector of substrings rather than individual
substrings assigned to separate objects.

HTH,
Dennis

On Sat, Jun 18, 2011 at 1:36 AM, Vijayan Padmanabhan
<padmanabhan.vijayan at gmail.com> wrote: