1
votes

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.

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

1 Answers

1
votes

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)