SparkR:如何制作 "INDEX MATCH / VLOOKUP"
SparkR : How To make a "INDEX MATCH / VLOOKUP"
SPARKR 中的索引匹配/VLOOKUP
我正在尝试在 Rstudio 中使用 SparkR 包进行“索引匹配/vlookup”,以前有人做过吗?我正在尝试使用函数 locate 在普通 RStudio 中使用函数 match 来使用相同的方法,但我收到一条无法使用两列定位的消息,所以我做了一个循环,但也没有用.. .有人对此有任何线索吗?
iUWYData <- SparkR::nrow(UWYData)
for(i in iUWYData){
UWYData[i,2] = LoBUWY_Data[SparkR::locate(UWYData[i,1], LoBUWY_Data$ICRF_ID),"Version"]
}
或
UWYData$Version = LoBUWY_Data[SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID),"Version"]
但我收到了这些消息:
Error in UWYData[i, 1]: Expressions other than filtering predicates are not supported in the first parameter of extract operator [ or subset() method.
traceback:
eval(parse(text = code), envir = envir)
test(Premium_rate_Index_script_v1 = Premium_rate_Index_script_v1)
LoBUWY_Data[SparkR::locate(UWYData[i, 1], LoBUWY_Data$ICRF_ID), "Version"]
LoBUWY_Data[SparkR::locate(UWYData[i, 1], LoBUWY_Data$ICRF_ID), "Version"]
SparkR::locate(UWYData[i, 1], LoBUWY_Data$ICRF_ID)
UWYData[i, 1]
UWYData[i, 1]
stop(paste0("Expressions other than filtering predicates are not supported ", "in the first parameter of extract operator [ or subset() method."))
和
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘locate’ for signature ‘"Column", "Column"’
traceback:
eval(parse(text = code), envir = envir)
test(Premium_rate_Index_script_v1 = Premium_rate_Index_script_v1)
LoBUWY_Data[SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID), "Version"]
LoBUWY_Data[SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID), "Version"]
SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID)
(function (classes, fdef, mtable)
使用SparkR::join
.
UWYData <- SparkR::createDataFrame(data.frame(
id = 1:5
))
LoBUWY_Data <- SparkR::createDataFrame(data.frame(
ICRF_ID = 1:4,
Version = 11:14
))
result <- SparkR::join(
UWYData,
LoBUWY_Data,
UWYData$id == LoBUWY_Data$ICRF_ID,
joinType = "left_outer"
)
SparkR::collect(result)
#> id ICRF_ID Version
#> 1 1 1 11
#> 2 3 3 13
#> 3 5 NA NA
#> 4 4 4 14
#> 5 2 2 12
SPARKR 中的索引匹配/VLOOKUP
我正在尝试在 Rstudio 中使用 SparkR 包进行“索引匹配/vlookup”,以前有人做过吗?我正在尝试使用函数 locate 在普通 RStudio 中使用函数 match 来使用相同的方法,但我收到一条无法使用两列定位的消息,所以我做了一个循环,但也没有用.. .有人对此有任何线索吗?
iUWYData <- SparkR::nrow(UWYData)
for(i in iUWYData){
UWYData[i,2] = LoBUWY_Data[SparkR::locate(UWYData[i,1], LoBUWY_Data$ICRF_ID),"Version"]
}
或
UWYData$Version = LoBUWY_Data[SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID),"Version"]
但我收到了这些消息:
Error in UWYData[i, 1]: Expressions other than filtering predicates are not supported in the first parameter of extract operator [ or subset() method. traceback: eval(parse(text = code), envir = envir) test(Premium_rate_Index_script_v1 = Premium_rate_Index_script_v1) LoBUWY_Data[SparkR::locate(UWYData[i, 1], LoBUWY_Data$ICRF_ID), "Version"] LoBUWY_Data[SparkR::locate(UWYData[i, 1], LoBUWY_Data$ICRF_ID), "Version"] SparkR::locate(UWYData[i, 1], LoBUWY_Data$ICRF_ID) UWYData[i, 1] UWYData[i, 1] stop(paste0("Expressions other than filtering predicates are not supported ", "in the first parameter of extract operator [ or subset() method."))
和
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘locate’ for signature ‘"Column", "Column"’
traceback: eval(parse(text = code), envir = envir) test(Premium_rate_Index_script_v1 = Premium_rate_Index_script_v1) LoBUWY_Data[SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID), "Version"] LoBUWY_Data[SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID), "Version"] SparkR::locate(UWYData$ICRF_ID, LoBUWY_Data$ICRF_ID) (function (classes, fdef, mtable)
使用SparkR::join
.
UWYData <- SparkR::createDataFrame(data.frame(
id = 1:5
))
LoBUWY_Data <- SparkR::createDataFrame(data.frame(
ICRF_ID = 1:4,
Version = 11:14
))
result <- SparkR::join(
UWYData,
LoBUWY_Data,
UWYData$id == LoBUWY_Data$ICRF_ID,
joinType = "left_outer"
)
SparkR::collect(result)
#> id ICRF_ID Version
#> 1 1 1 11
#> 2 3 3 13
#> 3 5 NA NA
#> 4 4 4 14
#> 5 2 2 12