[R] paste adjacent elements matching string
    Henrique Dallazuanna 
    wwwhsd at gmail.com
       
    Sat Dec  5 14:51:28 CET 2009
    
    
  
Try this also:
sapply(grep("string$", vec), function(idx)paste(vec[idx + 0:1], collapse = ""))
On Fri, Dec 4, 2009 at 11:42 PM, Jill Hollenbach <jillah at sbcglobal.net> wrote:
> Hi all,
> I would like to combine elements of a vector:
>
> vec <- c("astring",  "b", "cstring",  "d", "e")
>  > vec
> [1] "astring" "b"       "cstring" "d"       "e"
>
> such that for every element that contains  "string" at the end, it is
> combined with the next element, so that I get this:
>
>  > res
> [1] "astringb" "cstringd" "e"
>
> Any help is much appreciated, still learning.
>
> Many thanks,
> Jill
>
>
>
>
> ________________________________________________
>     Jill Hollenbach, PhD, MPH
>     Associate Staff Scientist
>     Center for Genetics
>     Children's Hospital Oakland Research Institute
>     jhollenbach at chori.org
>     skype: jillah11
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
    
    
More information about the R-help
mailing list