Vote count:
0
R novice here with what is probably a silly/ simple question.
I am trying to use R to find and replace within a vector "census.new" (basically trying to use R to do what excel does with find/ replace). However, because the original data (what I am searching for) overlaps partially with what I am trying to replace, I am ending up with some funky results.
I am trying to replace 2 with 2008b, 3 with 2009a, etc.
census.new<-sub("2","2008b", census.new, fixed=TRUE)
census.new<-sub("3","2009a", census.new, fixed=TRUE)
census.new<-sub("4","2009b", census.new, fixed=TRUE)
census.new<-sub("5","2010a", census.new, fixed=TRUE)
census.new<-sub("8","2011b", census.new, fixed=TRUE)
census.new<-sub("10","2012a", census.new, fixed=TRUE)
census.new<-sub("11","2012b", census.new, fixed=TRUE)
census.new<-sub("12","2013a", census.new, fixed=TRUE)
census.new<-sub("13","2013b", census.new, fixed=TRUE)
table(census.new)
The resulting table is:
2002020202013babbb 2009a 2009b 202013ba00202012bbb 202013ba009a
6268 3129 3129 3129 3129
20202013baa 20202013bab 2020202013baaa 2020202013babb
3129 3129 3129 3129
Thanks in advance!
asked 2 mins ago
Find and replace without backsearching
Aucun commentaire:
Enregistrer un commentaire