Re: [R] replace string values with numbers

2012-09-26 Thread JiangZhengyu
Hi Guys, Both of your ways worked. Thanks a lot for your help! Best,Zhengyu > Date: Wed, 26 Sep 2012 16:28:29 -0700 > From: smartpink...@yahoo.com > Subject: Re: [R] replace string values with numbers > To: zhyjiang2...@hotmail.com > CC: r-help@r-project.org; dwinsem...@comc

Re: [R] replace string values with numbers

2012-09-26 Thread arun
Hi, You can also try these: Gene<-read.table(text=" P1 P2 P3  CG CG GG -- --  AC  -- AC CC AC  --  AC ",header=TRUE,sep="") Gene<-sapply(Gene,as.character) Gene<-data.frame(gsub("GG","3",Gene))  Gene #  P1 P2 P3 #1 CG CG  3 #2 -- -- AC #3 -- AC CC #4 AC -- AC # str(Gene) #'data.frame':    4 obs.

Re: [R] replace string values with numbers

2012-09-26 Thread David Winsemius
On Sep 26, 2012, at 2:27 PM, David Winsemius wrote: > > On Sep 26, 2012, at 12:52 PM, JiangZhengyu wrote: >> >> Hi everyone, I have a data frame Gene with SNPs eg. P1 P2 P3 >> CG CG GG >> -- -- AC >> -- AC CC >> AC -- AC I tried to replace all the GG with a value 3. >> Gene[Gene=="GG

Re: [R] replace string values with numbers

2012-09-26 Thread David Winsemius
On Sep 26, 2012, at 12:52 PM, JiangZhengyu wrote: > > > > > Hi everyone, I have a data frame Gene with SNPs eg. P1 P2 P3 > CG CG GG > -- -- AC > -- AC CC > AC -- AC I tried to replace all the GG with a value 3. > Gene[Gene=="GG"]<-3 It always give me: Warning in `[<-.factor`(`*tmp