A different approach than those other people listed would be to change
the vector into a matrix (by setting its dimension, if you don't need
to keep the original vector) and then applying paste along one of the
dimensions.  Obviously, you'd need to pad the end of the vector with
NAs or empty strings.  Since you have a working solution, I won't
write code... but this approach might be a little easier to scale if,
for example, you need to concatenate every three elements of the
vector.
Best,
Gray

On Fri, Dec 4, 2009 at 5:42 PM, Jill Hollenbach <jil...@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
>     jhollenb...@chori.org
>     skype: jillah11
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>



-- 
Gray Calhoun

Assistant Professor of Economics
Iowa State University

______________________________________________
R-help@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.

Reply via email to