dimanche 22 février 2015

manipulate strings R to produce specific output

I have character vectors like this



sol=c("119","911","*","ab","ba","*","*","abcd","bcda","abcd","cdab","abcd","dabc","*","*","*","*")


I want to take a vector at a time and produce an output as below.


What is the quickest way to do the same? Basically, I want to start a new line wherever there is *. If there are consecutive * then I want only one new line. Consecutive non * elements should be printed on a new line and in case of consecutive non * elements, if there is any repeating element then it shouldn't get printed



119 911
ab ba
abcd bcda cdab dabc


I am thinking of writing a for loop and printing elements till i encounter a *. But not sure how to ensure that how to treat consecutive * to produce a single new line and also not sure how to remove repeating element from a consecutive list of non * elements


Aucun commentaire:

Enregistrer un commentaire