How to set table() and prop.table() as columns in a new data frame?












0














I'm fairly new to R, and I'm working with a grade distribution dataset, where there's a column called "Grade" that contains all letter grades for a class (column is in the main data frame called "Stat322"). So, Stat322$Grade would look like 'A+', 'A-', 'A', 'A', 'B', 'B-', 'B-', etc.



What I've been trying to do is create a new data frame with 3 columns called "Grade", "Freq", and "Prop" (latter 2 are frequency, and proportion for Stat322$Grade). What I did was



freq <- table(Stat322$Grade)
prop <- prop.table(freq)
newDataFrame <- data.frame <- ("Grade" = c(grade names, A+, A, A-, ...,),
"Frequency" = freq, "Proportion" = prop)


But it seems freq and prop already contain the grade names as a column, and the column names and the data table come out looking very messy, where the column names are Grade, Freq.Var1, Freq.Freq, Prop.Var1, Prop.Freq, with 3 of the 5 columns being duplicates of grade names.



How can I extract just the numerical values from freq, prop, and add it to my new data frame with the proper column names? Thanks, and I appreciate your help.










share|improve this question


















  • 1




    please post a few rows of the data set, per the instructions in How to create a Minimal, Complete, and Verifiable Example.
    – Len Greski
    Nov 26 '17 at 19:05
















0














I'm fairly new to R, and I'm working with a grade distribution dataset, where there's a column called "Grade" that contains all letter grades for a class (column is in the main data frame called "Stat322"). So, Stat322$Grade would look like 'A+', 'A-', 'A', 'A', 'B', 'B-', 'B-', etc.



What I've been trying to do is create a new data frame with 3 columns called "Grade", "Freq", and "Prop" (latter 2 are frequency, and proportion for Stat322$Grade). What I did was



freq <- table(Stat322$Grade)
prop <- prop.table(freq)
newDataFrame <- data.frame <- ("Grade" = c(grade names, A+, A, A-, ...,),
"Frequency" = freq, "Proportion" = prop)


But it seems freq and prop already contain the grade names as a column, and the column names and the data table come out looking very messy, where the column names are Grade, Freq.Var1, Freq.Freq, Prop.Var1, Prop.Freq, with 3 of the 5 columns being duplicates of grade names.



How can I extract just the numerical values from freq, prop, and add it to my new data frame with the proper column names? Thanks, and I appreciate your help.










share|improve this question


















  • 1




    please post a few rows of the data set, per the instructions in How to create a Minimal, Complete, and Verifiable Example.
    – Len Greski
    Nov 26 '17 at 19:05














0












0








0


0





I'm fairly new to R, and I'm working with a grade distribution dataset, where there's a column called "Grade" that contains all letter grades for a class (column is in the main data frame called "Stat322"). So, Stat322$Grade would look like 'A+', 'A-', 'A', 'A', 'B', 'B-', 'B-', etc.



What I've been trying to do is create a new data frame with 3 columns called "Grade", "Freq", and "Prop" (latter 2 are frequency, and proportion for Stat322$Grade). What I did was



freq <- table(Stat322$Grade)
prop <- prop.table(freq)
newDataFrame <- data.frame <- ("Grade" = c(grade names, A+, A, A-, ...,),
"Frequency" = freq, "Proportion" = prop)


But it seems freq and prop already contain the grade names as a column, and the column names and the data table come out looking very messy, where the column names are Grade, Freq.Var1, Freq.Freq, Prop.Var1, Prop.Freq, with 3 of the 5 columns being duplicates of grade names.



How can I extract just the numerical values from freq, prop, and add it to my new data frame with the proper column names? Thanks, and I appreciate your help.










share|improve this question













I'm fairly new to R, and I'm working with a grade distribution dataset, where there's a column called "Grade" that contains all letter grades for a class (column is in the main data frame called "Stat322"). So, Stat322$Grade would look like 'A+', 'A-', 'A', 'A', 'B', 'B-', 'B-', etc.



What I've been trying to do is create a new data frame with 3 columns called "Grade", "Freq", and "Prop" (latter 2 are frequency, and proportion for Stat322$Grade). What I did was



freq <- table(Stat322$Grade)
prop <- prop.table(freq)
newDataFrame <- data.frame <- ("Grade" = c(grade names, A+, A, A-, ...,),
"Frequency" = freq, "Proportion" = prop)


But it seems freq and prop already contain the grade names as a column, and the column names and the data table come out looking very messy, where the column names are Grade, Freq.Var1, Freq.Freq, Prop.Var1, Prop.Freq, with 3 of the 5 columns being duplicates of grade names.



How can I extract just the numerical values from freq, prop, and add it to my new data frame with the proper column names? Thanks, and I appreciate your help.







r






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '17 at 18:42









Max

1012




1012








  • 1




    please post a few rows of the data set, per the instructions in How to create a Minimal, Complete, and Verifiable Example.
    – Len Greski
    Nov 26 '17 at 19:05














  • 1




    please post a few rows of the data set, per the instructions in How to create a Minimal, Complete, and Verifiable Example.
    – Len Greski
    Nov 26 '17 at 19:05








1




1




please post a few rows of the data set, per the instructions in How to create a Minimal, Complete, and Verifiable Example.
– Len Greski
Nov 26 '17 at 19:05




please post a few rows of the data set, per the instructions in How to create a Minimal, Complete, and Verifiable Example.
– Len Greski
Nov 26 '17 at 19:05












1 Answer
1






active

oldest

votes


















0














You can extract the column in the following manner



freq <- as.vector(table(Stat322$Grade))
prop <- as.vector(prop.table(freq))



then you can create a new data frame by



newDataFrame <- data.frame("Grade" = c("A+", "A", "A-","B","B+","A",...), "Frequency" = freq, "Proportion" = prop)






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%2f47499685%2fhow-to-set-table-and-prop-table-as-columns-in-a-new-data-frame%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









    0














    You can extract the column in the following manner



    freq <- as.vector(table(Stat322$Grade))
    prop <- as.vector(prop.table(freq))



    then you can create a new data frame by



    newDataFrame <- data.frame("Grade" = c("A+", "A", "A-","B","B+","A",...), "Frequency" = freq, "Proportion" = prop)






    share|improve this answer


























      0














      You can extract the column in the following manner



      freq <- as.vector(table(Stat322$Grade))
      prop <- as.vector(prop.table(freq))



      then you can create a new data frame by



      newDataFrame <- data.frame("Grade" = c("A+", "A", "A-","B","B+","A",...), "Frequency" = freq, "Proportion" = prop)






      share|improve this answer
























        0












        0








        0






        You can extract the column in the following manner



        freq <- as.vector(table(Stat322$Grade))
        prop <- as.vector(prop.table(freq))



        then you can create a new data frame by



        newDataFrame <- data.frame("Grade" = c("A+", "A", "A-","B","B+","A",...), "Frequency" = freq, "Proportion" = prop)






        share|improve this answer












        You can extract the column in the following manner



        freq <- as.vector(table(Stat322$Grade))
        prop <- as.vector(prop.table(freq))



        then you can create a new data frame by



        newDataFrame <- data.frame("Grade" = c("A+", "A", "A-","B","B+","A",...), "Frequency" = freq, "Proportion" = prop)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 0:02









        varun khanna

        91




        91






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f47499685%2fhow-to-set-table-and-prop-table-as-columns-in-a-new-data-frame%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

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values