HI, Dear R-community, I have one vector of the following string,
> test<-c("H.1.Y", "N.0.E", "G.1.N", "E.0.P", "W.2.G", "W.4.G", "W.3.W", "W.0.N", "D.1.H") > test [1] "H.1.Y" "N.0.E" "G.1.N" "E.0.P" "W.2.G" "W.4.G" "W.3.W" "W.0.N" "D.1.H" *I want to change them into* "H{1}Y" "N{0}E" "G{1}N" "W{2}G" "E{0}P" "W{4}G" "W{3}W" "W{0}N" "D{1}H" I tried the following codes: > new_t<-gsub(".?.", "{?}", test) > new_t [1] "{?}{?}{?}" "{?}{?}{?}" "{?}{?}{?}" "{?}{?}{?}" "{?}{?}{?}" "{?}{?}{?}" [7] "{?}{?}{?}" "{?}{?}{?}" "{?}{?}{?}" > new_t<-gsub(".N.", "{N}", test) > new_t [1] "H.1.Y" "N.0.E" "G.1.N" "E.0.P" "W.2.G" "W.4.G" "W.3.W" "W.0.N" "D.1.H" > new_t<-gsub(".*.", "{*}", test) > new_t [1] "{*}" "{*}" "{*}" "{*}" "{*}" "{*}" "{*}" "{*}" "{*}" Can anyone help me with this? Thanks! -- Sincerely, Changbin -- [[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.