Formatting tables in PDF so that column values are not repeated for aggregate










0















I'm sorry the question title is confusing, I'm not sure how to label this problem I'm trying to solve.



I'm using the ToothGrowth dataset to produce a table that output into pdf, using the following code:



library(grid)
library(extraGrid)

> dput(ToothGrowth)
structure(list(len = c(4.2, 11.5, 7.3, 5.8, 6.4, 10, 11.2, 11.2,
5.2, 7, 16.5, 16.5, 15.2, 17.3, 22.5, 17.3, 13.6, 14.5, 18.8,
15.5, 23.6, 18.5, 33.9, 25.5, 26.4, 32.5, 26.7, 21.5, 23.3, 29.5,
15.2, 21.5, 17.6, 9.7, 14.5, 10, 8.2, 9.4, 16.5, 9.7, 19.7, 23.3,
23.6, 26.4, 20, 25.2, 25.8, 21.2, 14.5, 27.3, 25.5, 26.4, 22.4,
24.5, 24.8, 30.9, 26.4, 27.3, 29.4, 23), supp = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("OJ",
"VC"), class = "factor"), dose = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2)), class = "data.frame", row.names = c(NA, -60L))

pdf("Test1.pdf", height = 20, width = 10)
grid.table(ToothGrowth, rows = NULL, theme = ttheme_minimal())
dev.off()


As you can see in the output (see image below), the dose and supp column values are repeated throughout. However, I want to format the table so that the dose and supp values are not repeated throughout, I've attached another photo to show you what exactly I want.



Would appreciate some help with this, because I'm unsure if the solution lies in the data wrangling or the pdf output code.



Existing format
enter image description here



Desired format



enter image description here










share|improve this question
























  • Have a closer look at the R-Tag also: R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. Provide minimal, reproducible, representative example(s) along with the desired end result. Use dput() for data and specify all non-base packages with library calls. Do not embed pictures for data or code, use indented code blocks. For statistics questions, use stats.stackexchange.com.

    – Andre Elrico
    Nov 16 '18 at 9:30















0















I'm sorry the question title is confusing, I'm not sure how to label this problem I'm trying to solve.



I'm using the ToothGrowth dataset to produce a table that output into pdf, using the following code:



library(grid)
library(extraGrid)

> dput(ToothGrowth)
structure(list(len = c(4.2, 11.5, 7.3, 5.8, 6.4, 10, 11.2, 11.2,
5.2, 7, 16.5, 16.5, 15.2, 17.3, 22.5, 17.3, 13.6, 14.5, 18.8,
15.5, 23.6, 18.5, 33.9, 25.5, 26.4, 32.5, 26.7, 21.5, 23.3, 29.5,
15.2, 21.5, 17.6, 9.7, 14.5, 10, 8.2, 9.4, 16.5, 9.7, 19.7, 23.3,
23.6, 26.4, 20, 25.2, 25.8, 21.2, 14.5, 27.3, 25.5, 26.4, 22.4,
24.5, 24.8, 30.9, 26.4, 27.3, 29.4, 23), supp = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("OJ",
"VC"), class = "factor"), dose = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2)), class = "data.frame", row.names = c(NA, -60L))

pdf("Test1.pdf", height = 20, width = 10)
grid.table(ToothGrowth, rows = NULL, theme = ttheme_minimal())
dev.off()


As you can see in the output (see image below), the dose and supp column values are repeated throughout. However, I want to format the table so that the dose and supp values are not repeated throughout, I've attached another photo to show you what exactly I want.



Would appreciate some help with this, because I'm unsure if the solution lies in the data wrangling or the pdf output code.



Existing format
enter image description here



Desired format



enter image description here










share|improve this question
























  • Have a closer look at the R-Tag also: R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. Provide minimal, reproducible, representative example(s) along with the desired end result. Use dput() for data and specify all non-base packages with library calls. Do not embed pictures for data or code, use indented code blocks. For statistics questions, use stats.stackexchange.com.

    – Andre Elrico
    Nov 16 '18 at 9:30













0












0








0








I'm sorry the question title is confusing, I'm not sure how to label this problem I'm trying to solve.



I'm using the ToothGrowth dataset to produce a table that output into pdf, using the following code:



library(grid)
library(extraGrid)

> dput(ToothGrowth)
structure(list(len = c(4.2, 11.5, 7.3, 5.8, 6.4, 10, 11.2, 11.2,
5.2, 7, 16.5, 16.5, 15.2, 17.3, 22.5, 17.3, 13.6, 14.5, 18.8,
15.5, 23.6, 18.5, 33.9, 25.5, 26.4, 32.5, 26.7, 21.5, 23.3, 29.5,
15.2, 21.5, 17.6, 9.7, 14.5, 10, 8.2, 9.4, 16.5, 9.7, 19.7, 23.3,
23.6, 26.4, 20, 25.2, 25.8, 21.2, 14.5, 27.3, 25.5, 26.4, 22.4,
24.5, 24.8, 30.9, 26.4, 27.3, 29.4, 23), supp = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("OJ",
"VC"), class = "factor"), dose = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2)), class = "data.frame", row.names = c(NA, -60L))

pdf("Test1.pdf", height = 20, width = 10)
grid.table(ToothGrowth, rows = NULL, theme = ttheme_minimal())
dev.off()


As you can see in the output (see image below), the dose and supp column values are repeated throughout. However, I want to format the table so that the dose and supp values are not repeated throughout, I've attached another photo to show you what exactly I want.



Would appreciate some help with this, because I'm unsure if the solution lies in the data wrangling or the pdf output code.



Existing format
enter image description here



Desired format



enter image description here










share|improve this question
















I'm sorry the question title is confusing, I'm not sure how to label this problem I'm trying to solve.



I'm using the ToothGrowth dataset to produce a table that output into pdf, using the following code:



library(grid)
library(extraGrid)

> dput(ToothGrowth)
structure(list(len = c(4.2, 11.5, 7.3, 5.8, 6.4, 10, 11.2, 11.2,
5.2, 7, 16.5, 16.5, 15.2, 17.3, 22.5, 17.3, 13.6, 14.5, 18.8,
15.5, 23.6, 18.5, 33.9, 25.5, 26.4, 32.5, 26.7, 21.5, 23.3, 29.5,
15.2, 21.5, 17.6, 9.7, 14.5, 10, 8.2, 9.4, 16.5, 9.7, 19.7, 23.3,
23.6, 26.4, 20, 25.2, 25.8, 21.2, 14.5, 27.3, 25.5, 26.4, 22.4,
24.5, 24.8, 30.9, 26.4, 27.3, 29.4, 23), supp = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("OJ",
"VC"), class = "factor"), dose = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2)), class = "data.frame", row.names = c(NA, -60L))

pdf("Test1.pdf", height = 20, width = 10)
grid.table(ToothGrowth, rows = NULL, theme = ttheme_minimal())
dev.off()


As you can see in the output (see image below), the dose and supp column values are repeated throughout. However, I want to format the table so that the dose and supp values are not repeated throughout, I've attached another photo to show you what exactly I want.



Would appreciate some help with this, because I'm unsure if the solution lies in the data wrangling or the pdf output code.



Existing format
enter image description here



Desired format



enter image description here







r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 10:11









Uwe Keim

27.7k32134216




27.7k32134216










asked Nov 16 '18 at 9:17









PryorePryore

199111




199111












  • Have a closer look at the R-Tag also: R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. Provide minimal, reproducible, representative example(s) along with the desired end result. Use dput() for data and specify all non-base packages with library calls. Do not embed pictures for data or code, use indented code blocks. For statistics questions, use stats.stackexchange.com.

    – Andre Elrico
    Nov 16 '18 at 9:30

















  • Have a closer look at the R-Tag also: R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. Provide minimal, reproducible, representative example(s) along with the desired end result. Use dput() for data and specify all non-base packages with library calls. Do not embed pictures for data or code, use indented code blocks. For statistics questions, use stats.stackexchange.com.

    – Andre Elrico
    Nov 16 '18 at 9:30
















Have a closer look at the R-Tag also: R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. Provide minimal, reproducible, representative example(s) along with the desired end result. Use dput() for data and specify all non-base packages with library calls. Do not embed pictures for data or code, use indented code blocks. For statistics questions, use stats.stackexchange.com.

– Andre Elrico
Nov 16 '18 at 9:30





Have a closer look at the R-Tag also: R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization and general computing. Provide minimal, reproducible, representative example(s) along with the desired end result. Use dput() for data and specify all non-base packages with library calls. Do not embed pictures for data or code, use indented code blocks. For statistics questions, use stats.stackexchange.com.

– Andre Elrico
Nov 16 '18 at 9:30












1 Answer
1






active

oldest

votes


















1














You can use:



TG1 <- ToothGrowth # make a copy in this case, its a "build-in" dataset

inds <- duplicated(TG1[,2:3]) # use duplicated in the respective column combination

TG1[inds, 2:3] <- NA # replace all dupe rows for your cols 2 and 3

#TG1$supp <- as.character(TG1$supp) # if you want to use "", you need to convert from factor to character first.
#TG1[inds, 2:3] <- "" # try out what works better for you.

pdf("Test1.pdf", height = 20, width = 10)
grid.table(TG1, rows = NULL, theme = ttheme_minimal())
dev.off()





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%2f53334743%2fformatting-tables-in-pdf-so-that-column-values-are-not-repeated-for-aggregate%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









    1














    You can use:



    TG1 <- ToothGrowth # make a copy in this case, its a "build-in" dataset

    inds <- duplicated(TG1[,2:3]) # use duplicated in the respective column combination

    TG1[inds, 2:3] <- NA # replace all dupe rows for your cols 2 and 3

    #TG1$supp <- as.character(TG1$supp) # if you want to use "", you need to convert from factor to character first.
    #TG1[inds, 2:3] <- "" # try out what works better for you.

    pdf("Test1.pdf", height = 20, width = 10)
    grid.table(TG1, rows = NULL, theme = ttheme_minimal())
    dev.off()





    share|improve this answer





























      1














      You can use:



      TG1 <- ToothGrowth # make a copy in this case, its a "build-in" dataset

      inds <- duplicated(TG1[,2:3]) # use duplicated in the respective column combination

      TG1[inds, 2:3] <- NA # replace all dupe rows for your cols 2 and 3

      #TG1$supp <- as.character(TG1$supp) # if you want to use "", you need to convert from factor to character first.
      #TG1[inds, 2:3] <- "" # try out what works better for you.

      pdf("Test1.pdf", height = 20, width = 10)
      grid.table(TG1, rows = NULL, theme = ttheme_minimal())
      dev.off()





      share|improve this answer



























        1












        1








        1







        You can use:



        TG1 <- ToothGrowth # make a copy in this case, its a "build-in" dataset

        inds <- duplicated(TG1[,2:3]) # use duplicated in the respective column combination

        TG1[inds, 2:3] <- NA # replace all dupe rows for your cols 2 and 3

        #TG1$supp <- as.character(TG1$supp) # if you want to use "", you need to convert from factor to character first.
        #TG1[inds, 2:3] <- "" # try out what works better for you.

        pdf("Test1.pdf", height = 20, width = 10)
        grid.table(TG1, rows = NULL, theme = ttheme_minimal())
        dev.off()





        share|improve this answer















        You can use:



        TG1 <- ToothGrowth # make a copy in this case, its a "build-in" dataset

        inds <- duplicated(TG1[,2:3]) # use duplicated in the respective column combination

        TG1[inds, 2:3] <- NA # replace all dupe rows for your cols 2 and 3

        #TG1$supp <- as.character(TG1$supp) # if you want to use "", you need to convert from factor to character first.
        #TG1[inds, 2:3] <- "" # try out what works better for you.

        pdf("Test1.pdf", height = 20, width = 10)
        grid.table(TG1, rows = NULL, theme = ttheme_minimal())
        dev.off()






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 10:10

























        answered Nov 16 '18 at 9:38









        Andre ElricoAndre Elrico

        5,79311230




        5,79311230





























            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%2f53334743%2fformatting-tables-in-pdf-so-that-column-values-are-not-repeated-for-aggregate%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

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            政党

            天津地下鉄3号線