0
我有兩個SparkR DataFrame,newHiresDF
和salesTeamDF
。我想根據newHiresDF$name
的值salesTeamDF$name
獲得newHiresDF
的子集,但我無法找到一種方法來實現此目的。以下是我嘗試的代碼。根據與另一個DataFrame的列值匹配的列值對子集SparkR DataFrame
#Create DataFrames
newHires <- data.frame(name = c("Thomas", "George", "Bill", "John"),
surname = c("Smith", "Williams", "Brown", "Taylor"))
salesTeam <- data.frame(name = c("Thomas", "Bill", "George"),
surname = c("Martin", "Clark", "Williams"))
newHiresDF <- createDataFrame(newHires)
salesTeamDF <- createDataFrame(salesTeam)
display(newHiresDF)
#Try to subset newHiresDF based on name values in salesTeamDF
#All of the below result in errors
NHsubset1 <- filter(newHiresDF, newHiresDF$name %in% salesTeamDF$name)
NHsubset2 <- filter(newHiresDF, intersect(select(newHiresDF, 'name'),
select(salesTeamDF, 'name')))
NHsubset3 <- newHiresDF[newHiresDF$name %in% salesTeamDF$name,] #This is how it would be done in R
#What I'd like NHsubset to look like:
name surname
1 Thomas Smith
2 George Williams
3 Bill Brown
如果您願意,PySpark代碼也可以工作。
剛剛意識到這是https://stackoverflow.com/questions/43095208/subset-dataframe-based-on-matching-values-in-another-dataframe-pyspark-1-6-的近重複1但這個問題還沒有得到解答。 –