I am relatively new on SparkR, and I am planning to transfer a for loop into a foreach loop in SparkR (R/3.3.3 & Spark/2.2.0).
I have searched on stackoverflow, the only relevant thread is: SparkR foreach loop
But it gives only the workaround by using other operations.
From what I see, there is a sparkr
package exist (https://amplab-extras.github.io/SparkR-pkg/rdocs/1.2/index.html) and contains foreach
function, but I really do not understand its use cases, which I will need some help/example from the community to help.
My example in original R code is following:
uniqueID <- unique(dataset$ID)
maxValueVector <- c()
for(id in uniqueID){
maxValueVector <- c(maximums, max(dataset[which(dataset$ID == id), ]$value))
}
I understand that the line in for loop should be break into several lines, but is there an example I can start with, such as the example foreach
code I can start with? Thanks a lot!
p.s. dataset
contains 2 columns: ID
and value
.