[R] comparing and changing(swaping) the value of columns from two diffrent data farmes

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sun Jun 12 17:41:15 CEST 2022


Is this some sort of homework? This list has a no homework policy.

If not, please show us your attempt to solve the problem. You seem to
be asking us to do your work for you, which is not a good way to learn
R. Show us your attempt and the error messages and/or incorrect
results you got. You will improve your R skills faster this way. IMO
only, of course. The specifications you provided seem to require
fairly basic data manipulations that you should really learn how to do
yourself.

Also...
Thanks for the reproducible example -- that is a good way to get a
helpful response. But please give us the code that creates the example
rather than just providing the text, which requires us to read and
convert it ourselves, an extra step. In general, if we can just rerun
your code it makes it easier to help ... which makes it more likely
that someone will give you a useful response.

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 Sun, Jun 12, 2022 at 7:07 AM anteneh asmare <hanatezera using gmail.com> wrote:
>
> I have the following two data frames
> Data frame 1
> "SNPID" "OA"    "EA"
> "snp001"        "C"     "A"
> "snp002"        "G"     "A"
> "snp003"        "C"     "A"
> "snp004"        "G"     "A"
> "snp005"        "C"     "T"
>
> Data frame 2
> SNPID   OA      EA      id00001 id00002 id00003 id00004 id00005
> snp001     A    C        1.01                      2                      0.97
>           1.97                    1.99
> snp002    A     G        1.02                     2                        1
>          2                            2
> snp003    C     A         1                      1.03                       2
>           0                            1
> snp004   A      G          1.02                    1.99                      2
>              1.02                           1.98
> snp005  C       T            1                        0                      1.01
>                     1                           1
>
> I want to  if  OA s and EAs in data frame 2 is the same as OAs and EAs
>  data frame 1 in such case I want to keep all information in data
> fram2 as it is . However if   OA s and EAs in data frame 2 is
> different from OAs and EAs  data frame 1, I want to change OA s and
> EAs in data frame 2 to  OAs and EAs  data frame 1 and   I want to
> redefine the values of the dosages (ids) of the variant (the dosage d
> for the i-th individual and the j-th variant would become d_ij
> new=2-dij.
> Dosage [j,]=2-dosage[j,]
> My desire data frame looks like
> Dataframe new
> SNPID"  "OA"       "EA"        id00001  id00002 id00003 id00004 id00005
> "snp001"        "C"     "A"     2-1.01            2- 2    2-    0.97           2-1.97
>     2-1.99
> "snp002"        "G"     "A"     2- 1.02              2- 2                   2-1
>   2-2                     2- 2
> "snp003"        "C"     "A"       1                    1.03                         2
>             0                          1
> "snp004"        "G"     "A"     2-1.02                   2-1.99
> 2-2                    2-1.02                    2-1.98
> "snp005"        "C"     "T"          1                        0
> 1.01                           1                                1
> Dose any one can help me the r code for the above.
> Kind regards,
> Hana
>
> ______________________________________________
> R-help using 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.



More information about the R-help mailing list