[R] String manipulation
Jannis
bt_jannis at yahoo.de
Wed Mar 9 01:57:28 CET 2011
Dennis,
If I understand you correctly (your example does not point unambiguously
to one unique solution...)
you could try:
dummy<- c('ac','ac','c','ac','ac','c')
dummy.rle<-rle(dummy)
result <- paste(dummy.rle$values,dummy.rle$lengths,collapse='_',sep='')
You may need to remove the '1' in dummy.rle$lengths to get exactly what
you wanted.
HTH
Jannis
On 03/09/2011 12:33 AM, Denis Kazakiewicz wrote:
> Dear [R] people
> Could you please help with following
>
>
> How to convert a vector
>
> 'ac','ac','c','ac','ac','c'
>
> into a single string
> 'ac2_c_ac2_c'
>
>
> Thank you in advance
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list