Message-ID: <1362427519.51310.YahooMailNeo@web142606.mail.bf1.yahoo.com>
Date: 2013-03-04T20:05:19Z
From: arun
Subject: A problem with text manipulation
In-Reply-To: <CA+dpOJ=0nwgC94RUbRhXUHHg3Vx+K5=cZ9CWVwK9DpBCeL0dzg@mail.gmail.com>
Hi,
You could use:
res<-unsplit(lapply(split(Vec,Vec),function(x) if(length(x)>1) c(head(x,1),paste0(head(x,-1),seq_along(head(x,-1)))) else x),Vec)
?res
# [1] "B"? "B1" "C"? "E"? "B2" "E1" "E2" "D"? "D1" "A"
A.K.
----- Original Message -----
From: Christofer Bogaso <bogaso.christofer at gmail.com>
To: r-help <r-help at r-project.org>
Cc:
Sent: Monday, March 4, 2013 2:13 PM
Subject: [R] A problem with text manipulation
Hello again,
Let say I have following vector:
set.seed(1)
Vec <- sample(LETTERS[1:5], 10, replace = TRUE)
Vec
Now with each repeated letter, I like to add suffix programatically.
Therefore I want to get following vector:
c("B", "B1", "C", "E", "B2", "E1", "E2", "D", "D1", "A")
Can somebody tell me how to achieve that?
Thanks and regards,
______________________________________________
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.