Re: [R] Replacing strings to numbers

2013-07-02 Thread arun
Hi, Not sure how your data looks like.  May be this helps. dat1<- read.table(text=" col1 AA-50 AT-34 TT-57 TT-45 TA-42 ",sep="",header=TRUE,stringsAsFactors=FALSE) vec1<-gsub("\\-.*","",dat1[,1]) vec2<- ifelse(vec1=="AA",-1,ifelse(vec1=="AT",0, ifelse(vec1=="TT",1,NA))) library(stringr)  abs(vec2

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