[R] Substitute value
chris201
chris.r.bennett at btinternet.com
Fri Mar 8 11:23:18 CET 2013
Hi,
I have a large data frame and within this there is one column which contains
individual codes (eg. 1.1234.2a.2). I am splitting these codes into their 4
components using strsplit (eg. "1", "1234", "2a", "2"). However there are
some individual codes which do not have a last component (eg. 2.4356.3b. ),
I want to give these codes a "1" as their last component (eg. 2.4356.3b.1)
but I can't get it to work.
This is my example and attempt:
sim.code<-c("1.1234.1a.1","1.1234.1a.2","1.3245.2c.5","4.6743.3c.","4.3254.6b.4","3.5463.2a.")
sim.val<-c(4,5,3,6,4,7)
sim.df<-data.frame(sim.code,sim.val)
sim.df$sim.code2<-sub(".$",".1",sim.df$sim.code)
sim.df
but this changes all the ends to ".1"
Thanks,
Chris
--
View this message in context: http://r.789695.n4.nabble.com/Substitute-value-tp4660699.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list