[R] Drop last numeral
Nutter, Benjamin
NutterB at ccf.org
Tue Jan 12 20:42:47 CET 2010
Data<-c("1131", "1132", "1731" ,"1732" ,"1821" ,"1822", "2221" ,"2222",
"2241" ,"2242","414342" ,"414371" ,"414372")
Bldgid<-substring(as.character(Data),1,nchar(Data)-1)
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of LCOG1
Sent: Tuesday, January 12, 2010 1:37 PM
To: r-help at r-project.org
Subject: [R] Drop last numeral
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 at 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.
===================================
P Please consider the environment before printing this e-mail
Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News & World Report (2009).
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.
Confidentiality Note: This message is intended for use\...{{dropped:13}}
More information about the R-help
mailing list