Qnob
Qnob

Reputation: 31

which() Function in SystemML

I’m a developer want to use SystemMl for running R-Code from our business people on a Spark cluster.

I’ve studied http://apache.github.io/systemml/dml-language-reference , however, haven’t found a implementation of the R function “which” or any alternative functionality. Has anyone an idea how I could

Given

v = c(1,4,NA,2, 5, NA)

Expect indexes where value meets condition = int[] 2 5

v2 = which(v>2)

Expect indexes where is.na returns TRUE = int[] 3 6

v3 = which(is.na(v))

I’ve already considered the functions replace() and removeEmpty(), but they don’t exactly meets my needs.

Thanks a lot in advance Kuno

Upvotes: 1

Views: 42

Answers (1)

mboehm7
mboehm7

Reputation: 115

Just in case someone else stumbles over the same problem. R's which can be emulated with the following workaround:

v2 = removeEmpty(target=seq(1,length(v)) * (v>2), margin="rows")

Furthermore, SystemML does not allow NA, so you would need to replace it with 0 or NaN (e.g., 0/0=NaN). The extraction would then look like (v==0) or (v!=v), where the latter accounts for the fact that any comparison with a NaN is false and so NaN is the only value that is not equal to itself.

Upvotes: 0

Related Questions