# create a sample data frame df <- data.frame(x = c(1, 1, 2, 2, 3, 3), y = c(4, 6, 2, 8, 1, 9)) print(df) # use the aggregate function to calculate the average of y values for each x value avg_y <- aggregate(y ~ x, data = df, FUN = mean) # view the result avg_y