How I can change the order of the levels of a factor in a Label Attribute? I want to implement this R command:
(Label<- relevel(Label, ref = "Yes")
How can I do that ?
How I can change the order of the levels of a factor in a Label Attribute? I want to implement this R command:
(Label<- relevel(Label, ref = "Yes")
How can I do that ?
 
    
     
    
    You could use the Execute R operator. Here's an example that changes the levels of the label in the iris data set. If you view the RapidMiner log you can see the print statements that show the structures.
<?xml version="1.0" encoding="UTF-8"?><process version="7.2.003">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="7.2.003" expanded="true" name="Process">
    <process expanded="true">
      <operator activated="true" class="retrieve" compatibility="7.2.003" expanded="true" height="68" name="Retrieve Iris" width="90" x="112" y="85">
    <parameter key="repository_entry" value="//Samples/data/Iris"/>
      </operator>
      <operator activated="true" class="r_scripting:execute_r" compatibility="7.2.000" expanded="true" height="103" name="Execute R" width="90" x="246" y="85">
    <parameter key="script" value="# rm_main is a mandatory function, 
# the number of arguments has to be the number of input ports (can be none)
rm_main = function(data)
{
    print('Hello, world!')
    # output can be found in Log View
    
    # your code goes here

	data$label = factor(data$label)
	data2 = data
	data2$label = relevel(data2$label, ref = 'Iris-virginica')
	print(str(data))
	print(str(data2))
	
    return(list(data, data2))
}
"/>
      </operator>
      <connect from_op="Retrieve Iris" from_port="output" to_op="Execute R" to_port="input 1"/>
      <connect from_op="Execute R" from_port="output 1" to_port="result 1"/>
      <connect from_op="Execute R" from_port="output 2" to_port="result 2"/>
      <portSpacing port="source_input 1" spacing="0"/>
      <portSpacing port="sink_result 1" spacing="0"/>
      <portSpacing port="sink_result 2" spacing="0"/>
      <portSpacing port="sink_result 3" spacing="0"/>
    </process>
  </operator>
</process>
I observe that the id and label roles are removed after the R script but this can be fixed by using the Set Role operator.
