How to Create a Weighted Frequency Table in R (Example Code)

This article explains how to create a weighted frequency table in the R programming language.

Introduction of Example Data

my_df <- data.frame(x = c(LETTERS[1:5], "A", "C"),  # Example data
                    w = 11:17)
my_df                                               # Display data in RStudio console
#   x  w
# 1 A 11
# 2 B 12
# 3 C 13
# 4 D 14
# 5 E 15
# 6 A 16
# 7 C 17

Example: How to Make a Weighted Frequency Distribution Table

install.packages("questionr")                       # Install questionr package
library("questionr")                                # Load questionr package
wtd.table(x = my_df$x, weights = my_df$w)           # Return weighted frequency table
#  A  B  C  D  E 
# 27 12 30 14 15

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top