![]() |
VOOZH | about |
Stratified sampling involves splitting a population into different groups based on a common characteristic and then randomly selecting members from each group. This method is useful when we want to ensure that each subgroup is represented in the sample. In this article , we will explore how to implement stratified sampling using R programming language.
We divide the population into groups and select a fixed number of members from each group to form the final sample.
We install and load the dplyr package to manipulate data and perform group-wise sampling.
We create a data frame containing 600 entries, with equal numbers of Teachers, Students, Workforce and Guests, each having a randomly generated GPA.
We group the data by category and select 15 samples from each group using random sampling.
We check how many records are selected from each group in the final sample.
Output:
We divide the population into groups and select a specific fraction of members from each group to form the final sample.
We install and load the dplyr package to enable data manipulation and sampling functions.
We create the same data frame with 600 rows and four groups, each having 150 entries and a GPA score.
We use the group-wise sampling function to select 20 percent of data from each group.
We check how many records were selected from each group after applying fraction-based sampling.
Output:
We implemented stratified sampling in R programming language using two methods, fixed number of rows and fraction of rows.