Re: [R] How to get a substring from a string

2014-01-15 Thread arun
Hi, Try:   sub("~.*","",string) #[1] "yab" #or  as.character(as.formula(string)[[2]]) #[1] "yab" A.K. On Wednesday, January 15, 2014 9:40 AM, "Yuan, Rebecca" wrote: Hello all, I would like to get a substring (first few characters till ~) from a string I can think of way of doing so by > s

Re: [R] How to get a substring from a string

2014-01-15 Thread Yuan, Rebecca
Hello A.K., This gives more flexibility to substract the string, thanks very much! Cheers, Rebecca -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Wednesday, January 15, 2014 10:43 AM To: R help Cc: Yuan, Rebecca Subject: Re: [R] How to get a substring from a

Re: [R] How to get a substring from a string

2014-01-15 Thread PIKAL Petr
an, Rebecca > Sent: Wednesday, January 15, 2014 3:39 PM > To: R help > Subject: [R] How to get a substring from a string > > Hello all, > > I would like to get a substring (first few characters till ~) from a > string > > I can think of way of doing so by > > &g

Re: [R] How to get a substring from a string

2014-01-15 Thread Mohammad Tanvir Ahamed
Hi ! Try it  st<-'yab~a+b+c' strsplit(st,"~")[[1]][1]    Best regards ...  Tanvir Ahamed Göteborg, Sweden From: "Yuan, Rebecca" To: R help Sent: Wednesday, 15 January 2014, 15:38 Subject: [R] How

Re: [R] How to get a substring from a string

2014-01-15 Thread Yuan, Rebecca
This works! Thanks very much! From: Mohammad Tanvir Ahamed [mailto:mashra...@yahoo.com] Sent: Wednesday, January 15, 2014 9:48 AM To: Yuan, Rebecca; R help Subject: Re: [R] How to get a substring from a string Hi ! Try it st<-'yab~a+b+c' strsplit(st,"~")

[R] How to get a substring from a string

2014-01-15 Thread Yuan, Rebecca
Hello all, I would like to get a substring (first few characters till ~) from a string I can think of way of doing so by > string<-'yab~a+b+c' > x<-substring(string,1,3) > x [1] "yab" But if I do not know the length of the first word before ~ sign, how can I get it out from the whole string?