Re: [R] Replacing strings to numbers

2013-07-02 Thread arun
c1=="AT",0, ifelse(vec1=="TT",1,NA))) library(stringr)  abs(vec2-as.numeric(unlist( str_extract_all(dat1[,1],"[0-9]+" #[1] 51 34 56 44 NA A.K. - Original Message - From: Jeremy Ng To: r-help@r-project.org Cc: Sent: Tuesday, July 2, 2013 8:31 AM Subject:

Re: [R] Replacing strings to numbers

2013-07-02 Thread Prof Brian Ripley
On 02/07/2013 13:31, Jeremy Ng wrote: Hi guys, I was wondering if any one is able to help me on a problem that I was stuck with for a long time. It involves the replacement of character strings with numbers. The character string can take on only 3 possible values, for instance: AA AT TT I woul

[R] Replacing strings to numbers

2013-07-02 Thread Jeremy Ng
Hi guys, I was wondering if any one is able to help me on a problem that I was stuck with for a long time. It involves the replacement of character strings with numbers. The character string can take on only 3 possible values, for instance: AA AT TT I would want R to replace AT with 0. Between A