Update a column in df2 by matching patterns in columns in df1 & df2 using R
问题 I have 2 data frames like this TEAM <- c("PE","PE","MPI","TDT","HPT","ATD") CODE <- c(NA,"F","A","H","G","D") df1 <- data.frame(TEAM,CODE) CODE <- c(NA,"F100","A234","D664","H435","G123","A666","D345","G324",NA) TEAM <- c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA) df2 <- data.frame(CODE,TEAM) I am trying to update the TEAM in df2 by matching the first letter in code column in df1 with the code column in df2 My desired output for df2 CODE TEAM 1 NA PE 2 F100 PE 3 A234 MPI 4 D664 ATD 5 H435 TDT 6 G123 HPT