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
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.
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
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
4 matches
Mail list logo