Sorry if the question is a bit confusing. I'm working with two different data frames in R. The first one is listed below and consists of a "Name" column along with a few other numeric variables.
Name <- c("John Smith", "John Smith", "John Smith", "John Smith", "John Smith", "Sam Smith", "Sam Smith", "Sam Smith", "Sam Smith", "Sam Smith")
pfx_z <- c(1.5, 0.78, 1.21, 0.54, 0.67, 1.00, 1.54, 1.32, 1.20, 0.98)
release_speed <- c(79.1, 80.3, 82.1, 80.3, 81.4, 84.3, 85.4, 85.1, 82.4, 86.5)
df_ch <- data.frame(Name, pfx_z, release_speed)
This first data frame consists of the individual observations for a person named John Smith and a person named Sam Smith. What I'm looking to do is add more variables to this data frame that list the average values for another variable for each person. Here's the other data frame:
Name <- c("John Smith", "Sam Smith")
pfx_z1 <- c(1.87, 1.65)
release_speed1 <- c(94.5, 95.2)
avg_df <- data.frame(Name, pfx_z1, release_speed1)
The end goal here is to add John Smith and Sam Smith's pfx_z1 and release_speed1 into ch_df. I'm aiming for it to look something like this:
Name <- c("John Smith", "John Smith", "John Smith", "John Smith", "John Smith", "Sam Smith", "Sam Smith", "Sam Smith", "Sam Smith", "Sam Smith")
pfx_z <- c(1.5, 0.78, 1.21, 0.54, 0.67, 1.00, 1.54, 1.32, 1.20, 0.98)
release_speed <- c(79.1, 80.3, 82.1, 80.3, 81.4, 84.3, 85.4, 85.1, 82.4, 86.5)
pfx_z1 <- c(1.87, 1.87, 1.87, 1.87, 1.87, 1.65, 1.65, 1.65, 1.65, 1.65)
release_speed1 <- c(94.5, 94.5, 94.5, 94.5, 94.5, 95.2, 95.2, 95.2, 95.2, 95.2)
df_ch <- data.frame(Name, pfx_z, release_speed, pfx_z1, release_speed1)