[R] Drop last numeral
LCOG1
jroll at lcog.org
Tue Jan 12 19:36:35 CET 2010
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.
More information about the R-help
mailing list