Frequency Table for Categorical Data
Suppuse your data file is in MS Excel to read an Excel file as follows:
> library(readxl)
> setwd("/Users/mdfazlulkarimpatwary/documents/Rtraining/")
> data <- read_excel("Cheat.xlsx")
> data

Now to see frequency of the attribute marital the following commands:
freq_m=table(data$marital)
print(freq_m)
Divorced Married Single
3 7 5
barplot(freq_m)

prob_m <- freq_m / sum(freq_m)
print(prob_m)
Divorced Married Single
0.2000000 0.4666667 0.3333333
cumf_m <- cumsum(freq_m)
print("cumulative Frequency Table")
print(cumf_m)
Divorced Married Single
3 10 15
Now combining all the results in a data frame:

To create a pie chart from the frequency table:
colors <- c("red", "blue", "green")
png("marital_status_pie.png", width = 800, height = 600)


Statlearner
Statlearner