filing in TRUE/FALSE in column of dataframe A based on information in dataframe B












-1















I searched for other topics, but didn't find anything which was really matching what I was looking for.



My dataframes:



UN_match excerpt:



country country_code   emissions sector_code     year
Austria AT 65779.1172 1.AA 2005
Austria AT 62430.4336 1.AA 2006
Austria AT 59108.4180 1.AA 2007
Austria AT 58656.6719 1.AA 2008
Austria AT 55252.9922 1.AA 2009
Austria AT 58317.9570 1.AA 2010
Austria AT 55898.7344 1.AA 2011
Austria AT 53886.8242 1.AA 2012
Austria AT 53923.7578 1.AA 2013
Austria AT 50087.0000 1.AA 2014
Austria AT 51978.9609 1.AA 2015
Austria AT 52990.2305 1.AA 2016
Belgium BE 103917.1484 1.AA 2005
Belgium BE 102263.9297 1.AA 2006
Belgium BE 100104.8906 1.AA 2007
Belgium BE 99960.6328 1.AA 2008
Belgium BE 92900.2188 1.AA 2009
Belgium BE 96538.8047 1.AA 2010
Belgium BE 87202.2188 1.AA 2011
Belgium BE 86242.7656 1.AA 2012
Belgium BE 86289.1562 1.AA 2013
Belgium BE 80720.1406 1.AA 2014
Belgium BE 84283.8438 1.AA 2015
Belgium BE 84081.2031 1.AA 2016


ETS_match



     country country_code     value year smaller1.AA
Austria AT 16539.659 2005 0
Austria AT 15275.065 2006 0
Austria AT 14124.646 2007 0
Austria AT 14572.511 2008 0
Austria AT 12767.555 2009 0
Austria AT 15506.112 2010 0
Austria AT 15131.551 2011 0
Austria AT 13121.434 2012 0
Austria AT 8074.514 2013 0
Austria AT 6426.135 2014 0
Austria AT 7514.263 2015 0
Austria AT 7142.937 2016 0
Belgium BE 25460.856 2005 0
Belgium BE 24099.282 2006 0
Belgium BE 23706.084 2007 0
Belgium BE 23166.180 2008 0
Belgium BE 21185.552 2009 0
Belgium BE 22073.616 2010 0
Belgium BE 18950.876 2011 0
Belgium BE 17463.388 2012 0
Belgium BE 16728.267 2013 0
Belgium BE 15230.243 2014 0
Belgium BE 16053.800 2015 0
Belgium BE 15027.777 2016 0


I want to add TRUE or FALSE into ETS_match$smaller1.AA based on whether ETS_match$value < UN_match$emissions is true or false. This should be done for every row.



I tried some things myself with mutate and if_else, but didn't manage to finish it.



It should look like this:



     country country_code     value year smaller1.AA
Austria AT 16539.659 2005 TRUE
Austria AT 15275.065 2006 TRUE
Austria AT 14124.646 2007 TRUE


I know this is probably very basic, but I would be happy about any kind of help.



Best wishes,



nordsee










share|improve this question



























    -1















    I searched for other topics, but didn't find anything which was really matching what I was looking for.



    My dataframes:



    UN_match excerpt:



    country country_code   emissions sector_code     year
    Austria AT 65779.1172 1.AA 2005
    Austria AT 62430.4336 1.AA 2006
    Austria AT 59108.4180 1.AA 2007
    Austria AT 58656.6719 1.AA 2008
    Austria AT 55252.9922 1.AA 2009
    Austria AT 58317.9570 1.AA 2010
    Austria AT 55898.7344 1.AA 2011
    Austria AT 53886.8242 1.AA 2012
    Austria AT 53923.7578 1.AA 2013
    Austria AT 50087.0000 1.AA 2014
    Austria AT 51978.9609 1.AA 2015
    Austria AT 52990.2305 1.AA 2016
    Belgium BE 103917.1484 1.AA 2005
    Belgium BE 102263.9297 1.AA 2006
    Belgium BE 100104.8906 1.AA 2007
    Belgium BE 99960.6328 1.AA 2008
    Belgium BE 92900.2188 1.AA 2009
    Belgium BE 96538.8047 1.AA 2010
    Belgium BE 87202.2188 1.AA 2011
    Belgium BE 86242.7656 1.AA 2012
    Belgium BE 86289.1562 1.AA 2013
    Belgium BE 80720.1406 1.AA 2014
    Belgium BE 84283.8438 1.AA 2015
    Belgium BE 84081.2031 1.AA 2016


    ETS_match



         country country_code     value year smaller1.AA
    Austria AT 16539.659 2005 0
    Austria AT 15275.065 2006 0
    Austria AT 14124.646 2007 0
    Austria AT 14572.511 2008 0
    Austria AT 12767.555 2009 0
    Austria AT 15506.112 2010 0
    Austria AT 15131.551 2011 0
    Austria AT 13121.434 2012 0
    Austria AT 8074.514 2013 0
    Austria AT 6426.135 2014 0
    Austria AT 7514.263 2015 0
    Austria AT 7142.937 2016 0
    Belgium BE 25460.856 2005 0
    Belgium BE 24099.282 2006 0
    Belgium BE 23706.084 2007 0
    Belgium BE 23166.180 2008 0
    Belgium BE 21185.552 2009 0
    Belgium BE 22073.616 2010 0
    Belgium BE 18950.876 2011 0
    Belgium BE 17463.388 2012 0
    Belgium BE 16728.267 2013 0
    Belgium BE 15230.243 2014 0
    Belgium BE 16053.800 2015 0
    Belgium BE 15027.777 2016 0


    I want to add TRUE or FALSE into ETS_match$smaller1.AA based on whether ETS_match$value < UN_match$emissions is true or false. This should be done for every row.



    I tried some things myself with mutate and if_else, but didn't manage to finish it.



    It should look like this:



         country country_code     value year smaller1.AA
    Austria AT 16539.659 2005 TRUE
    Austria AT 15275.065 2006 TRUE
    Austria AT 14124.646 2007 TRUE


    I know this is probably very basic, but I would be happy about any kind of help.



    Best wishes,



    nordsee










    share|improve this question

























      -1












      -1








      -1








      I searched for other topics, but didn't find anything which was really matching what I was looking for.



      My dataframes:



      UN_match excerpt:



      country country_code   emissions sector_code     year
      Austria AT 65779.1172 1.AA 2005
      Austria AT 62430.4336 1.AA 2006
      Austria AT 59108.4180 1.AA 2007
      Austria AT 58656.6719 1.AA 2008
      Austria AT 55252.9922 1.AA 2009
      Austria AT 58317.9570 1.AA 2010
      Austria AT 55898.7344 1.AA 2011
      Austria AT 53886.8242 1.AA 2012
      Austria AT 53923.7578 1.AA 2013
      Austria AT 50087.0000 1.AA 2014
      Austria AT 51978.9609 1.AA 2015
      Austria AT 52990.2305 1.AA 2016
      Belgium BE 103917.1484 1.AA 2005
      Belgium BE 102263.9297 1.AA 2006
      Belgium BE 100104.8906 1.AA 2007
      Belgium BE 99960.6328 1.AA 2008
      Belgium BE 92900.2188 1.AA 2009
      Belgium BE 96538.8047 1.AA 2010
      Belgium BE 87202.2188 1.AA 2011
      Belgium BE 86242.7656 1.AA 2012
      Belgium BE 86289.1562 1.AA 2013
      Belgium BE 80720.1406 1.AA 2014
      Belgium BE 84283.8438 1.AA 2015
      Belgium BE 84081.2031 1.AA 2016


      ETS_match



           country country_code     value year smaller1.AA
      Austria AT 16539.659 2005 0
      Austria AT 15275.065 2006 0
      Austria AT 14124.646 2007 0
      Austria AT 14572.511 2008 0
      Austria AT 12767.555 2009 0
      Austria AT 15506.112 2010 0
      Austria AT 15131.551 2011 0
      Austria AT 13121.434 2012 0
      Austria AT 8074.514 2013 0
      Austria AT 6426.135 2014 0
      Austria AT 7514.263 2015 0
      Austria AT 7142.937 2016 0
      Belgium BE 25460.856 2005 0
      Belgium BE 24099.282 2006 0
      Belgium BE 23706.084 2007 0
      Belgium BE 23166.180 2008 0
      Belgium BE 21185.552 2009 0
      Belgium BE 22073.616 2010 0
      Belgium BE 18950.876 2011 0
      Belgium BE 17463.388 2012 0
      Belgium BE 16728.267 2013 0
      Belgium BE 15230.243 2014 0
      Belgium BE 16053.800 2015 0
      Belgium BE 15027.777 2016 0


      I want to add TRUE or FALSE into ETS_match$smaller1.AA based on whether ETS_match$value < UN_match$emissions is true or false. This should be done for every row.



      I tried some things myself with mutate and if_else, but didn't manage to finish it.



      It should look like this:



           country country_code     value year smaller1.AA
      Austria AT 16539.659 2005 TRUE
      Austria AT 15275.065 2006 TRUE
      Austria AT 14124.646 2007 TRUE


      I know this is probably very basic, but I would be happy about any kind of help.



      Best wishes,



      nordsee










      share|improve this question














      I searched for other topics, but didn't find anything which was really matching what I was looking for.



      My dataframes:



      UN_match excerpt:



      country country_code   emissions sector_code     year
      Austria AT 65779.1172 1.AA 2005
      Austria AT 62430.4336 1.AA 2006
      Austria AT 59108.4180 1.AA 2007
      Austria AT 58656.6719 1.AA 2008
      Austria AT 55252.9922 1.AA 2009
      Austria AT 58317.9570 1.AA 2010
      Austria AT 55898.7344 1.AA 2011
      Austria AT 53886.8242 1.AA 2012
      Austria AT 53923.7578 1.AA 2013
      Austria AT 50087.0000 1.AA 2014
      Austria AT 51978.9609 1.AA 2015
      Austria AT 52990.2305 1.AA 2016
      Belgium BE 103917.1484 1.AA 2005
      Belgium BE 102263.9297 1.AA 2006
      Belgium BE 100104.8906 1.AA 2007
      Belgium BE 99960.6328 1.AA 2008
      Belgium BE 92900.2188 1.AA 2009
      Belgium BE 96538.8047 1.AA 2010
      Belgium BE 87202.2188 1.AA 2011
      Belgium BE 86242.7656 1.AA 2012
      Belgium BE 86289.1562 1.AA 2013
      Belgium BE 80720.1406 1.AA 2014
      Belgium BE 84283.8438 1.AA 2015
      Belgium BE 84081.2031 1.AA 2016


      ETS_match



           country country_code     value year smaller1.AA
      Austria AT 16539.659 2005 0
      Austria AT 15275.065 2006 0
      Austria AT 14124.646 2007 0
      Austria AT 14572.511 2008 0
      Austria AT 12767.555 2009 0
      Austria AT 15506.112 2010 0
      Austria AT 15131.551 2011 0
      Austria AT 13121.434 2012 0
      Austria AT 8074.514 2013 0
      Austria AT 6426.135 2014 0
      Austria AT 7514.263 2015 0
      Austria AT 7142.937 2016 0
      Belgium BE 25460.856 2005 0
      Belgium BE 24099.282 2006 0
      Belgium BE 23706.084 2007 0
      Belgium BE 23166.180 2008 0
      Belgium BE 21185.552 2009 0
      Belgium BE 22073.616 2010 0
      Belgium BE 18950.876 2011 0
      Belgium BE 17463.388 2012 0
      Belgium BE 16728.267 2013 0
      Belgium BE 15230.243 2014 0
      Belgium BE 16053.800 2015 0
      Belgium BE 15027.777 2016 0


      I want to add TRUE or FALSE into ETS_match$smaller1.AA based on whether ETS_match$value < UN_match$emissions is true or false. This should be done for every row.



      I tried some things myself with mutate and if_else, but didn't manage to finish it.



      It should look like this:



           country country_code     value year smaller1.AA
      Austria AT 16539.659 2005 TRUE
      Austria AT 15275.065 2006 TRUE
      Austria AT 14124.646 2007 TRUE


      I know this is probably very basic, but I would be happy about any kind of help.



      Best wishes,



      nordsee







      r dataframe






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 11:34









      NordseeNordsee

      465




      465
























          3 Answers
          3






          active

          oldest

          votes


















          4














          Something like this, with dplyr, maybe:



          library(dplyr)
          UN_match %>% left_join(ETS_match) %>% # join the data
          mutate(smaller1.AA = value < emissions, TRUE, FALSE) %>% # add the true false
          select(country, country_code, value, year, smaller1.AA) # only useful columns


          But all your value are < of emission, so the data are rows are all TRUE in this case.



          Improved removing if_else, thanks @Rui Barradas.






          share|improve this answer





















          • 1





            You don't need if_else, just the condition is simpler.

            – Rui Barradas
            Nov 22 '18 at 11:50











          • Thank you very much for this. Most of the results will be TRUE, but there are also exceptions. The excerpt only showed "TRUE".

            – Nordsee
            Nov 22 '18 at 12:10



















          1














          If the datasets have the same number of rows and all the rows align correctly, you can just do:



          ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions





          share|improve this answer
























          • Yes, they are of the same length. And this little code did exactly what I needed. Thank you very much!

            – Nordsee
            Nov 22 '18 at 12:09



















          1














          Because the data you're working with are from two different data frames, you have either two options:




          1. Compare them independently

          2. Combine the data into one data frame.


          For 1, you can do something like



          ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions


          For 2, you could use merge to bring the data frames together.
          How to join (merge) data frames (inner, outer, left, right)?






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430068%2ffiling-in-true-false-in-column-of-dataframe-a-based-on-information-in-dataframe%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            Something like this, with dplyr, maybe:



            library(dplyr)
            UN_match %>% left_join(ETS_match) %>% # join the data
            mutate(smaller1.AA = value < emissions, TRUE, FALSE) %>% # add the true false
            select(country, country_code, value, year, smaller1.AA) # only useful columns


            But all your value are < of emission, so the data are rows are all TRUE in this case.



            Improved removing if_else, thanks @Rui Barradas.






            share|improve this answer





















            • 1





              You don't need if_else, just the condition is simpler.

              – Rui Barradas
              Nov 22 '18 at 11:50











            • Thank you very much for this. Most of the results will be TRUE, but there are also exceptions. The excerpt only showed "TRUE".

              – Nordsee
              Nov 22 '18 at 12:10
















            4














            Something like this, with dplyr, maybe:



            library(dplyr)
            UN_match %>% left_join(ETS_match) %>% # join the data
            mutate(smaller1.AA = value < emissions, TRUE, FALSE) %>% # add the true false
            select(country, country_code, value, year, smaller1.AA) # only useful columns


            But all your value are < of emission, so the data are rows are all TRUE in this case.



            Improved removing if_else, thanks @Rui Barradas.






            share|improve this answer





















            • 1





              You don't need if_else, just the condition is simpler.

              – Rui Barradas
              Nov 22 '18 at 11:50











            • Thank you very much for this. Most of the results will be TRUE, but there are also exceptions. The excerpt only showed "TRUE".

              – Nordsee
              Nov 22 '18 at 12:10














            4












            4








            4







            Something like this, with dplyr, maybe:



            library(dplyr)
            UN_match %>% left_join(ETS_match) %>% # join the data
            mutate(smaller1.AA = value < emissions, TRUE, FALSE) %>% # add the true false
            select(country, country_code, value, year, smaller1.AA) # only useful columns


            But all your value are < of emission, so the data are rows are all TRUE in this case.



            Improved removing if_else, thanks @Rui Barradas.






            share|improve this answer















            Something like this, with dplyr, maybe:



            library(dplyr)
            UN_match %>% left_join(ETS_match) %>% # join the data
            mutate(smaller1.AA = value < emissions, TRUE, FALSE) %>% # add the true false
            select(country, country_code, value, year, smaller1.AA) # only useful columns


            But all your value are < of emission, so the data are rows are all TRUE in this case.



            Improved removing if_else, thanks @Rui Barradas.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 22 '18 at 11:52

























            answered Nov 22 '18 at 11:45









            s_ts_t

            3,22321030




            3,22321030








            • 1





              You don't need if_else, just the condition is simpler.

              – Rui Barradas
              Nov 22 '18 at 11:50











            • Thank you very much for this. Most of the results will be TRUE, but there are also exceptions. The excerpt only showed "TRUE".

              – Nordsee
              Nov 22 '18 at 12:10














            • 1





              You don't need if_else, just the condition is simpler.

              – Rui Barradas
              Nov 22 '18 at 11:50











            • Thank you very much for this. Most of the results will be TRUE, but there are also exceptions. The excerpt only showed "TRUE".

              – Nordsee
              Nov 22 '18 at 12:10








            1




            1





            You don't need if_else, just the condition is simpler.

            – Rui Barradas
            Nov 22 '18 at 11:50





            You don't need if_else, just the condition is simpler.

            – Rui Barradas
            Nov 22 '18 at 11:50













            Thank you very much for this. Most of the results will be TRUE, but there are also exceptions. The excerpt only showed "TRUE".

            – Nordsee
            Nov 22 '18 at 12:10





            Thank you very much for this. Most of the results will be TRUE, but there are also exceptions. The excerpt only showed "TRUE".

            – Nordsee
            Nov 22 '18 at 12:10













            1














            If the datasets have the same number of rows and all the rows align correctly, you can just do:



            ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions





            share|improve this answer
























            • Yes, they are of the same length. And this little code did exactly what I needed. Thank you very much!

              – Nordsee
              Nov 22 '18 at 12:09
















            1














            If the datasets have the same number of rows and all the rows align correctly, you can just do:



            ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions





            share|improve this answer
























            • Yes, they are of the same length. And this little code did exactly what I needed. Thank you very much!

              – Nordsee
              Nov 22 '18 at 12:09














            1












            1








            1







            If the datasets have the same number of rows and all the rows align correctly, you can just do:



            ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions





            share|improve this answer













            If the datasets have the same number of rows and all the rows align correctly, you can just do:



            ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 11:44









            ClelandCleland

            1556




            1556













            • Yes, they are of the same length. And this little code did exactly what I needed. Thank you very much!

              – Nordsee
              Nov 22 '18 at 12:09



















            • Yes, they are of the same length. And this little code did exactly what I needed. Thank you very much!

              – Nordsee
              Nov 22 '18 at 12:09

















            Yes, they are of the same length. And this little code did exactly what I needed. Thank you very much!

            – Nordsee
            Nov 22 '18 at 12:09





            Yes, they are of the same length. And this little code did exactly what I needed. Thank you very much!

            – Nordsee
            Nov 22 '18 at 12:09











            1














            Because the data you're working with are from two different data frames, you have either two options:




            1. Compare them independently

            2. Combine the data into one data frame.


            For 1, you can do something like



            ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions


            For 2, you could use merge to bring the data frames together.
            How to join (merge) data frames (inner, outer, left, right)?






            share|improve this answer




























              1














              Because the data you're working with are from two different data frames, you have either two options:




              1. Compare them independently

              2. Combine the data into one data frame.


              For 1, you can do something like



              ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions


              For 2, you could use merge to bring the data frames together.
              How to join (merge) data frames (inner, outer, left, right)?






              share|improve this answer


























                1












                1








                1







                Because the data you're working with are from two different data frames, you have either two options:




                1. Compare them independently

                2. Combine the data into one data frame.


                For 1, you can do something like



                ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions


                For 2, you could use merge to bring the data frames together.
                How to join (merge) data frames (inner, outer, left, right)?






                share|improve this answer













                Because the data you're working with are from two different data frames, you have either two options:




                1. Compare them independently

                2. Combine the data into one data frame.


                For 1, you can do something like



                ETS_match$smaller1.AA <- ETS_match$value < UN_match$emissions


                For 2, you could use merge to bring the data frames together.
                How to join (merge) data frames (inner, outer, left, right)?







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 '18 at 11:48









                Ken OsborneKen Osborne

                111




                111






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430068%2ffiling-in-true-false-in-column-of-dataframe-a-based-on-information-in-dataframe%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'