我有2個dataframes這樣合併2個數據幀返回匹配測量名稱
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)
我想,它返回匹配測量,還返回行的方式來合併這2個數據幀的所有行是具有由另一個字符串連接的匹配度量。
我所需的輸出是
ID Type Measurement Function
A PASS Length Volume
B PASS Height Area
C FAIL Breadth Circumference
C FAIL Breadth_DSPT Circumference
我使用合併功能類似這樣拿到第3行,但我們如何匹配數據幀中的測量名稱去返回匹配的所有行?
df <- merge(df1,df2,by=c("ID","Type","Measurement"),all.x=T)
好像你試圖合併基於部分匹配的數據框?看看是否有幫助:http://stackoverflow.com/questions/10617377/merge-data-with-partial-match-in-r –
如果我理解正確,你需要使用模糊連接:https:// cran。 r-project.org/web/packages/fuzzyjoin/fuzzyjoin.pdf,因爲「寬度」和「寬度_DSPT」是相似的,但不相同。 – Mislav
串聯總是隻是「string_newpart」? – thelatemail