【发布时间】:2020-03-04 13:57:39
【问题描述】:
我有 2 个数据框。 1. df1 包含来自 OLAP 多维数据集的带有非结构化标题的销售数据。
df1 <- data.frame("[Time].[Fiscal Year].[Fiscal Year].[MEMBER_CAPTION]"= c("FY18","FY19","FY20"), "[Measures].[USD]"=c(100,200,300))
names(df1) <- c("[Time].[Fiscal Year].[Fiscal Year].[MEMBER_CAPTION]","[Measures].[USD]")
- df2 包含非结构化标头列表和相应的已清理标头。
df2<- data.frame("RawHeaderName"=c("[Time].[Fiscal Year]","[Measures].[USD]"),"ReportDisplayName"=c("FiscalYear","USD"))
我的要求是当 df2$RawHeaderName 值与 df1 标头匹配(模糊匹配)时,我需要将 df1 标头替换为 df2$ReportDisplayName 值。最终结果应该如下所示。
FinalOutput <- data.frame("FiscalYear" =c("FY18","FY19","FY20"),"USD"=c(100,200,300))
请帮我解决问题。 我已经尝试过 library("fuzzyjoin"),library("dplyr") 库,但没有运气。
【问题讨论】:
标签: r