Also try sub('[0-9]$', '', Data) [1] "113" "113" "173" "173" "182" "182" "222" "222" "224" [10] "224" "41434" "41437" "41437"
HTH, Dennis On Tue, Jan 12, 2010 at 10:36 AM, LCOG1 <jr...@lcog.org> wrote: > > Hello all, > Frustrated and i know you can help > > I need to drop the last numeral of each of my values in my data set. So > for > the following i have tried the ?substring but since i have to specify the > length, but because my data are of varying lengths it doenst work so well > > Data<-c("1131", "1132", "1731" ,"1732" ,"1821" ,"1822", "2221" ,"2222", > "2241" ,"2242","414342" ,"414371" ,"414372") > Bldgid<-substring(as.character(Data),1,3) > > returns: > "113" "113" "173" "173" "182" "182" "222" "222" "224" "224" "414" "414" > "414" > > but i want" > > "113", "113", "173" ,"173" ,"182" ,"182", "222" ,"222", "224" > ,"224","41434" > ,"41437" ,"41437") > > The values thats have more than 4 numerals are whats messing things up. > Tried ?formatC as well but couldn't get it to coerce things correctly. > Thanks for the help > > JR > -- > View this message in context: > http://n4.nabble.com/Drop-last-numeral-tp1012347p1012347.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. > [[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.