I have the following data set in data frameIDnumber? OA? EA? beta1? ? ? ? ? ? ? ? ? ? ? ? ?C? ? ? ?A? ? ? ?-0.052? ? ? ? ? ? ? ? ? ? ? ? ?G? ? ? ? A? ? ? ? 0.0983? ? ? ? ? ? ? ? ? ? ? ? ? G? ? ? ? T? ? ? ? -0.789....I want to change the sign of negative beta. If the negative value change to postive i want to switch its EA and OA.My desire result will beIDnumber? OA? EA? beta1? ? ? ? ? ? ? ? ? ? ? ? ?A? ? ? C? ? ?0.052? ? ? ? ? ? ? ? ? ? ? ? ?G? ? ? ? A? ? ? ? 0.0983? ? ? ? ? ? ? ? ? ? ? ? ? T? ? ? ? ?G? ? ? ? 0.789....Any one can help me with r codes??kind regards,Hana
Changing sign of columns and values
6 messages · hanatezera, Bert Gunter, Jim Lemon
This is a plain text list. Your html post got mangled (see below). You are more likely to get a useful response if you follow the posting guide (linked below) and post in plain text. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sat, Jun 11, 2022 at 3:27 PM hanatezera <hanatezera at gmail.com> wrote:
I have the following data set in data frameIDnumber OA EA beta1 C A -0.052 G A 0.0983 G T -0.789....I want to change the sign of negative beta. If the negative value change to postive i want to switch its EA and OA.My desire result will beIDnumber OA EA beta1 A C 0.052 G A 0.0983 T G 0.789....Any one can help me with r codes? kind regards,Hana
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hi Hana, I think this is what you want: # first read in your example mydf<-read.table(text= "IDnumber OA EA beta 1 C A -0.05 2 G A 0.098 3 G T -0.789", header=TRUE,stringsAsFactors=FALSE) # check it mydf IDnumber OA EA beta 1 1 C A -0.050 2 2 G A 0.098 3 3 G T -0.789 # change values of mydf$beta to absolute values mydf$beta<-abs(mydf$beta) mydf IDnumber OA EA beta 1 1 C A 0.050 2 2 G A 0.098 3 3 G T 0.789 Jim
On Sun, Jun 12, 2022 at 8:27 AM hanatezera <hanatezera at gmail.com> wrote:
I have the following data set in data frameIDnumber OA EA beta1 C A -0.052 G A 0.0983 G T -0.789....I want to change the sign of negative beta. If the negative value change to postive i want to switch its EA and OA.My desire result will beIDnumber OA EA beta1 A C 0.052 G A 0.0983 T G 0.789....Any one can help me with r codes? kind regards,Hana
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Dear jim thanks for your help! I want to change also the value of OA and EF simultaneously.For instance i am looking the datamydf IDnumber OA EA? beta1??????? 1? A? C? 0.0502??????? 2? G? A 0.0983??????? 3? T? ?G 0.789Best,?Hana? ? ? ? ? ? ? ? ? -------- Original message --------From: Jim Lemon <drjimlemon at gmail.com> Date: 6/12/22 1:59 AM (GMT+03:00) To: hanatezera <hanatezera at gmail.com>, r-help mailing list <r-help at r-project.org> Subject: Re: [R] Changing sign of columns and values Hi Hana,I think this is what you want:# first read in your examplemydf<-read.table(text="IDnumber? OA? EA? beta1?? C?????? A?????? -0.052?? G??????? A??????? 0.0983?? G??????? T??????? -0.789",header=TRUE,stringsAsFactors=FALSE)# check itmydf IDnumber OA EA?? beta1??????? 1? C? A -0.0502??????? 2? G? A? 0.0983??????? 3? G? T -0.789# change values of mydf$beta to absolute valuesmydf$beta<-abs(mydf$beta)mydf IDnumber OA EA? beta1??????? 1? C? A 0.0502??????? 2? G? A 0.0983??????? 3? G? T 0.789JimOn Sun, Jun 12, 2022 at 8:27 AM hanatezera <hanatezera at gmail.com> wrote:>> I have the following data set in data frameIDnumber? OA? EA? beta1???????????????????????? C?????? A?????? -0.052???????????????????????? G??????? A??????? 0.0983????????????????????????? G??????? T??????? -0.789....I want to change the sign of negative beta. If the negative value change to postive i want to switch its EA and OA.My desire result will beIDnumber? OA? EA? beta1???????????????????????? A????? C???? 0.052???????????????????????? G??????? A??????? 0.0983????????????????????????? T???????? G??????? 0.789....Any one can help me with r codes? kind regards,Hana>???????? [[alternative HTML version deleted]]>> ______________________________________________> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see> https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Hi Hana, I didn't look closely. The simplest rule that I can see is that the letters (nucleotides?) should be swapped if there has been a sign change in the beta value. Therefore: mydf<-read.table(text= "IDnumber OA EA beta 1 C A -0.05 2 G A 0.098 3 G T -0.789", header=TRUE,stringsAsFactors=FALSE) # logical vector marking the rows to be swapped swap_letters<-mydf$beta < 0 # save the OA values to be swapped newEA<-mydf$OA[swap_letters] # change the OAs to EAs mydf$OA[swap_letters]<-mydf$EA[swap_letters] # set the relevant EA values to the old OA values mydf$EA[swap_letters]<-newEA # change the beta values mydf$beta<-abs(mydf$beta) mydf Jim
On Sun, Jun 12, 2022 at 9:11 AM hanatezera <hanatezera at gmail.com> wrote:
Dear jim thanks for your help! I want to change also the value of OA and EF simultaneously. For instance i am looking the data mydf IDnumber OA EA beta 1 1 A C 0.050 2 2 G A 0.098 3 3 T G 0.789 Best, Hana -------- Original message -------- From: Jim Lemon <drjimlemon at gmail.com> Date: 6/12/22 1:59 AM (GMT+03:00) To: hanatezera <hanatezera at gmail.com>, r-help mailing list <r-help at r-project.org> Subject: Re: [R] Changing sign of columns and values Hi Hana, I think this is what you want: # first read in your example mydf<-read.table(text= "IDnumber OA EA beta 1 C A -0.05 2 G A 0.098 3 G T -0.789", header=TRUE,stringsAsFactors=FALSE) # check it mydf IDnumber OA EA beta 1 1 C A -0.050 2 2 G A 0.098 3 3 G T -0.789 # change values of mydf$beta to absolute values mydf$beta<-abs(mydf$beta) mydf IDnumber OA EA beta 1 1 C A 0.050 2 2 G A 0.098 3 3 G T 0.789 Jim On Sun, Jun 12, 2022 at 8:27 AM hanatezera <hanatezera at gmail.com> wrote:
I have the following data set in data frameIDnumber OA EA beta1 C A -0.052 G A 0.0983 G T -0.789....I want to change the sign of negative beta. If the negative value change to postive i want to switch its EA and OA.My desire result will beIDnumber OA EA beta1 A C 0.052 G A 0.0983 T G 0.789....Any one can help me with r codes? kind regards,Hana
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Dear Jim, Thanks a lot this is exactly i am looking for.Stay safe and blessed !Best,Hana -------- Original message --------From: Jim Lemon <drjimlemon at gmail.com> Date: 6/12/22 6:43 AM (GMT+03:00) To: hanatezera <hanatezera at gmail.com> Cc: r-help mailing list <r-help at r-project.org> Subject: Re: [R] Changing sign of columns and values Hi Hana,I didn't look closely. The simplest rule that I can see is that theletters (nucleotides?) should be swapped if there has been a signchange in the beta value. Therefore:mydf<-read.table(text="IDnumber? OA? EA? beta1?? C?????? A?????? -0.052?? G??????? A??????? 0.0983?? G??????? T??????? -0.789",header=TRUE,stringsAsFactors=FALSE)# logical vector marking the rows to be swappedswap_letters<-mydf$beta < 0# save the OA values to be swappednewEA<-mydf$OA[swap_letters]# change the OAs to EAsmydf$OA[swap_letters]<-mydf$EA[swap_letters]# set the relevant EA values to the old OA valuesmydf$EA[swap_letters]<-newEA# change the beta valuesmydf$beta<-abs(mydf$beta)mydfJimOn Sun, Jun 12, 2022 at 9:11 AM hanatezera <hanatezera at gmail.com> wrote:>> Dear jim thanks for your help! I want to change also the value of OA and EF simultaneously.> For instance i am looking the data> mydf> IDnumber OA EA? beta> 1??????? 1? A? C? 0.050> 2??????? 2? G? A 0.098> 3??????? 3? T?? G 0.789>> Best,> Hana>>>> -------- Original message --------> From: Jim Lemon <drjimlemon at gmail.com>> Date: 6/12/22 1:59 AM (GMT+03:00)> To: hanatezera <hanatezera at gmail.com>, r-help mailing list <r-help at r-project.org>> Subject: Re: [R] Changing sign of columns and values>> Hi Hana,> I think this is what you want:>> # first read in your example> mydf<-read.table(text=> "IDnumber? OA? EA? beta> 1?? C?????? A?????? -0.05> 2?? G??????? A??????? 0.098> 3?? G??????? T??????? -0.789",> header=TRUE,stringsAsFactors=FALSE)> # check it> mydf> IDnumber OA EA?? beta> 1??????? 1? C? A -0.050> 2??????? 2? G? A? 0.098> 3??????? 3? G? T -0.789> # change values of mydf$beta to absolute values> mydf$beta<-abs(mydf$beta)> mydf> IDnumber OA EA? beta> 1??????? 1? C? A 0.050> 2??????? 2? G? A 0.098> 3??????? 3? G? T 0.789>> Jim>> On Sun, Jun 12, 2022 at 8:27 AM hanatezera <hanatezera at gmail.com> wrote:> >> > I have the following data set in data frameIDnumber? OA? EA? beta1???????????????????????? C?????? A?????? -0.052???????????????????????? G??????? A??????? 0.0983????????????????????????? G??????? T??????? -0.789....I want to change the sign of negative beta. If the negative value change to postive i want to switch its EA and OA.My desire result will beIDnumber? OA? EA? beta1???????????????????????? A????? C???? 0.052???????????????????????? G??????? A??????? 0.0983????????????????????????? T???????? G??????? 0.789....Any one can help me with r codes? kind regards,Hana> >???????? [[alternative HTML version deleted]]> >> > ______________________________________________> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see> > https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code.