I have the following spark data frame called "clients":
ID VAR1 VAR2 VAR3
1 A F A1
2 C M B1
3 E F C1
4 C 0 B1
And I also have a dictionary of variables called "ref", which shows the unique values a variable can take, like this one:
Variables Values
VAR1 A
VAR1 B
VAR1 C
VAR1 D
VAR1 E
VAR2 F
VAR2 M
VAR3 A1
VAR3 B1
I want to replace those values that are not allowed for variables, with a default value like "-1", so I can have something like this:
ID VAR1 VAR2 VAR3
1 A F A1
2 C M B1
3 E F -1
4 C -1 B1
With data table library I would use something like this:
names <- colnames(clients)
for(var in names){
set(x = clients,
i = which(!clients[[var]] %in% ref[Variables == var]$Values),
j = var,
value = "-1")
I would like to know if there exist some similar solution to use with sparklyr.