completing tables in paired designs with missing levels The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceDrop factor levels in a subsetted data frameQuickly reading very large tables as dataframesElegant way to check for missing packages and install them?Remove rows with all or some NAs (missing values) in data.frameTools for making latex tables in Rrbindlist for factors with missing levelsR: zero padding for missing levels in group-by tablemissing factor level in RHow to complete missing factor levels in data frame?Filling missing levels

Can the DM override racial traits?

How to split my screen on my Macbook Air?

Who or what is the being for whom Being is a question for Heidegger?

What are these Gizmos at Izaña Atmospheric Research Center in Spain?

University's motivation for having tenure-track positions

Change bounding box of math glyphs in LuaTeX

Sort a list of pairs representing an acyclic, partial automorphism

If the empty set is a subset of every set, why write ... ∪ ∅?

Why did all the guest students take carriages to the Yule Ball?

Take groceries in checked luggage

Can a novice safely splice in wire to lengthen 5V charging cable?

Create an outline of font

Are my PIs rude or am I just being too sensitive?

Make it rain characters

Semisimplicity of the category of coherent sheaves?

What aspect of planet Earth must be changed to prevent the industrial revolution?

How does ice melt when immersed in water?

The variadic template constructor of my class cannot modify my class members, why is that so?

Wall plug outlet change

Simulating Exploding Dice

Did the new image of black hole confirm the general theory of relativity?

how can a perfect fourth interval be considered either consonant or dissonant?

Scientific Reports - Significant Figures

Why is superheterodyning better than direct conversion?



completing tables in paired designs with missing levels



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceDrop factor levels in a subsetted data frameQuickly reading very large tables as dataframesElegant way to check for missing packages and install them?Remove rows with all or some NAs (missing values) in data.frameTools for making latex tables in Rrbindlist for factors with missing levelsR: zero padding for missing levels in group-by tablemissing factor level in RHow to complete missing factor levels in data frame?Filling missing levels



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a repeated measures design with categorical variables. Let's say, participants reported their attitude ('Approve', 'Neutral', 'Disapprove') at time point 1 and 2. I then create a table with frequencies of response combinations.





# setup
set.seed(123)
library(tidyverse)

# made-up data
survey.data <- data.frame(
`1st survey` = c('Approve', 'Approve', 'Neutral', 'Approve'),
`2nd survey` = c('Approve', 'Disapprove', 'Approve', 'Neutral'),
`Counts` = c(79, 15, 86, 10),
check.names = FALSE
) %>%
tidyr::uncount(., Counts) %>%
tibble::as_tibble()

# table of counts
table("1" = survey.data$`1st survey`, "2" = survey.data$`2nd survey`)
#> 2
#> 1 Approve Disapprove Neutral
#> Approve 79 15 10
#> Neutral 86 0 0


Note here that since nobody chose the option "Disapprove" at time point-1, it is missing from the table. This is, of course, expected. But the function I want to use (rcompanion::cohenG) expects an equal number of rows and columns in a table. So I was wondering how I can change the code above to get the expected output here-



#> 2
#> 1 Approve Disapprove Neutral
#> Approve 79 15 10
#> Disapprove 0 0 0
#> Neutral 86 0 0









share|improve this question




























    0















    I have a repeated measures design with categorical variables. Let's say, participants reported their attitude ('Approve', 'Neutral', 'Disapprove') at time point 1 and 2. I then create a table with frequencies of response combinations.





    # setup
    set.seed(123)
    library(tidyverse)

    # made-up data
    survey.data <- data.frame(
    `1st survey` = c('Approve', 'Approve', 'Neutral', 'Approve'),
    `2nd survey` = c('Approve', 'Disapprove', 'Approve', 'Neutral'),
    `Counts` = c(79, 15, 86, 10),
    check.names = FALSE
    ) %>%
    tidyr::uncount(., Counts) %>%
    tibble::as_tibble()

    # table of counts
    table("1" = survey.data$`1st survey`, "2" = survey.data$`2nd survey`)
    #> 2
    #> 1 Approve Disapprove Neutral
    #> Approve 79 15 10
    #> Neutral 86 0 0


    Note here that since nobody chose the option "Disapprove" at time point-1, it is missing from the table. This is, of course, expected. But the function I want to use (rcompanion::cohenG) expects an equal number of rows and columns in a table. So I was wondering how I can change the code above to get the expected output here-



    #> 2
    #> 1 Approve Disapprove Neutral
    #> Approve 79 15 10
    #> Disapprove 0 0 0
    #> Neutral 86 0 0









    share|improve this question
























      0












      0








      0








      I have a repeated measures design with categorical variables. Let's say, participants reported their attitude ('Approve', 'Neutral', 'Disapprove') at time point 1 and 2. I then create a table with frequencies of response combinations.





      # setup
      set.seed(123)
      library(tidyverse)

      # made-up data
      survey.data <- data.frame(
      `1st survey` = c('Approve', 'Approve', 'Neutral', 'Approve'),
      `2nd survey` = c('Approve', 'Disapprove', 'Approve', 'Neutral'),
      `Counts` = c(79, 15, 86, 10),
      check.names = FALSE
      ) %>%
      tidyr::uncount(., Counts) %>%
      tibble::as_tibble()

      # table of counts
      table("1" = survey.data$`1st survey`, "2" = survey.data$`2nd survey`)
      #> 2
      #> 1 Approve Disapprove Neutral
      #> Approve 79 15 10
      #> Neutral 86 0 0


      Note here that since nobody chose the option "Disapprove" at time point-1, it is missing from the table. This is, of course, expected. But the function I want to use (rcompanion::cohenG) expects an equal number of rows and columns in a table. So I was wondering how I can change the code above to get the expected output here-



      #> 2
      #> 1 Approve Disapprove Neutral
      #> Approve 79 15 10
      #> Disapprove 0 0 0
      #> Neutral 86 0 0









      share|improve this question














      I have a repeated measures design with categorical variables. Let's say, participants reported their attitude ('Approve', 'Neutral', 'Disapprove') at time point 1 and 2. I then create a table with frequencies of response combinations.





      # setup
      set.seed(123)
      library(tidyverse)

      # made-up data
      survey.data <- data.frame(
      `1st survey` = c('Approve', 'Approve', 'Neutral', 'Approve'),
      `2nd survey` = c('Approve', 'Disapprove', 'Approve', 'Neutral'),
      `Counts` = c(79, 15, 86, 10),
      check.names = FALSE
      ) %>%
      tidyr::uncount(., Counts) %>%
      tibble::as_tibble()

      # table of counts
      table("1" = survey.data$`1st survey`, "2" = survey.data$`2nd survey`)
      #> 2
      #> 1 Approve Disapprove Neutral
      #> Approve 79 15 10
      #> Neutral 86 0 0


      Note here that since nobody chose the option "Disapprove" at time point-1, it is missing from the table. This is, of course, expected. But the function I want to use (rcompanion::cohenG) expects an equal number of rows and columns in a table. So I was wondering how I can change the code above to get the expected output here-



      #> 2
      #> 1 Approve Disapprove Neutral
      #> Approve 79 15 10
      #> Disapprove 0 0 0
      #> Neutral 86 0 0






      r






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 13:35









      Indrajeet PatilIndrajeet Patil

      1,609414




      1,609414






















          1 Answer
          1






          active

          oldest

          votes


















          2














          You can cast the responses to factors with three known levels



          levels <- c("Disapprove", "Neutral", "Approve")

          survey.data <- survey.data %>%
          mutate_at(vars(`1st survey`,
          `2nd survey`),
          factor, levels = levels)

          table(survey.data$`1st survey`,
          survey.data$`2nd survey`)
          #>
          #> Disapprove Neutral Approve
          #> Disapprove 0 0 0
          #> Neutral 0 0 86
          #> Approve 15 10 79


          Created on 2019-03-08 by the reprex package (v0.2.1)






          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%2f55064325%2fcompleting-tables-in-paired-designs-with-missing-levels%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You can cast the responses to factors with three known levels



            levels <- c("Disapprove", "Neutral", "Approve")

            survey.data <- survey.data %>%
            mutate_at(vars(`1st survey`,
            `2nd survey`),
            factor, levels = levels)

            table(survey.data$`1st survey`,
            survey.data$`2nd survey`)
            #>
            #> Disapprove Neutral Approve
            #> Disapprove 0 0 0
            #> Neutral 0 0 86
            #> Approve 15 10 79


            Created on 2019-03-08 by the reprex package (v0.2.1)






            share|improve this answer



























              2














              You can cast the responses to factors with three known levels



              levels <- c("Disapprove", "Neutral", "Approve")

              survey.data <- survey.data %>%
              mutate_at(vars(`1st survey`,
              `2nd survey`),
              factor, levels = levels)

              table(survey.data$`1st survey`,
              survey.data$`2nd survey`)
              #>
              #> Disapprove Neutral Approve
              #> Disapprove 0 0 0
              #> Neutral 0 0 86
              #> Approve 15 10 79


              Created on 2019-03-08 by the reprex package (v0.2.1)






              share|improve this answer

























                2












                2








                2







                You can cast the responses to factors with three known levels



                levels <- c("Disapprove", "Neutral", "Approve")

                survey.data <- survey.data %>%
                mutate_at(vars(`1st survey`,
                `2nd survey`),
                factor, levels = levels)

                table(survey.data$`1st survey`,
                survey.data$`2nd survey`)
                #>
                #> Disapprove Neutral Approve
                #> Disapprove 0 0 0
                #> Neutral 0 0 86
                #> Approve 15 10 79


                Created on 2019-03-08 by the reprex package (v0.2.1)






                share|improve this answer













                You can cast the responses to factors with three known levels



                levels <- c("Disapprove", "Neutral", "Approve")

                survey.data <- survey.data %>%
                mutate_at(vars(`1st survey`,
                `2nd survey`),
                factor, levels = levels)

                table(survey.data$`1st survey`,
                survey.data$`2nd survey`)
                #>
                #> Disapprove Neutral Approve
                #> Disapprove 0 0 0
                #> Neutral 0 0 86
                #> Approve 15 10 79


                Created on 2019-03-08 by the reprex package (v0.2.1)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 13:52









                dipetkovdipetkov

                1,48618




                1,48618





























                    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%2f55064325%2fcompleting-tables-in-paired-designs-with-missing-levels%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

                    1928 у кіно

                    Захаров Федір Захарович

                    Ель Греко