Question: # Assume your dataset is named 'county _ dataset' # Replace 'median _ edu' with the actual column name representing the level of education #

# Assume your dataset is named 'county_dataset'
# Replace 'median_edu' with the actual column name representing the level of education
# Generate a sample dataset for demonstration
set.seed(123)
county_dataset <- data.frame(
county_id =1:100,
median_edu = sample(c("below_hs","hs_diploma", "some_college", "bachelors"),100, replace = TRUE)
)
# Create a stratified sample
my.Stratified <- county_dataset %>%
group_by(median_edu)%>%
slice_sample(n = ifelse(median_edu == "below_hs",1,
ifelse(median_edu =="hs_diploma", 14,
ifelse(median_edu == "some_college", 17,
ifelse(median_edu == "bachelors", 4,0)
)
)
))%>%
ungroup()
# Print the resulting dataframe
print(my.Stratified)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!