[R] Extract part of a numer

arun smartpink111 at yahoo.com
Tue Apr 23 18:10:59 CEST 2013


Hi,
May be this helps:
set.seed(25)
dat1<- data.frame(ID=c("1001#01","1001#02","1001#03","1002#01","1002#02"),val=rnorm(5),stringsAsFactors=FALSE)
 dat1$ID<-as.numeric(gsub("#.*","",dat1$ID))
 dat1
#    ID        val
#1 1001 -0.2118336
#2 1001 -1.0415911
#3 1001 -1.1533076
#4 1002  0.3215315
#5 1002 -1.5001299
A.K.


>Hi all, 
>
>I have a database with a colume ID have the ID numbers like this1001#01, 1001#02, etc.. 
>
>How could I do to just extract 1001 out? 
>
>Thanks, 
>
>York



More information about the R-help mailing list