I have 2 dataframes like this
ID <- c("A","B","C")
Type <- c("PASS","PASS","FAIL")
Measurement <- c("Length","Height","Breadth")
Function <- c("Volume","Area","Circumference")
df1 <- data.frame(ID,Type,Measurement,Function)
ID <- c("A","B","C","C")
Type <- c("PASS","PASS","FAIL","FAIL")
Measurement <- c("Length","Height","Breadth","Breadth_DSPT")
df2 <- data.frame(ID,Type,Measurement)
I am trying to merge these 2 data frames in a way that it returns matching measurements and also returns rows that have the matching measurement concatenated by another string.
My desired output is
ID Type Measurement Function
A PASS Length Volume
B PASS Height Area
C FAIL Breadth Circumference
C FAIL Breadth_DSPT Circumference
I use the merge function like this to get the first 3 rows but how do we match the measurement names in the data frames to return all rows that have the match?
df <- merge(df1,df2,by=c("ID","Type","Measurement"),all.x=T)