#' Generate PMML elements that using 'NormDiscrete'
#'
#' Generate the 'NormContinuous' part for the whole PMML transformation segment
#' 'LocalTransformation'.
#'
#' @param featureName Character string indicating name of the discrete/categorical
#' variable that indicators will be generated from.
#' @param featureLevel Vector of float numbers indicating different levels/chategories
#' or the discrete variable.
#' @param newFieldName Character string indicating new name for the derived feature.
#' @param purpose Character string indicating type of 'NormContinuous', e.g.,
#' 'miss', 'dummy'.
#'
#' @return XML file representing PMML element 'LocalTransformation' that contains
#' 'DerivedField' with transformation 'NormDiscrete'.
#'
#' @export
#'
#' @examples
#' dummyMMID <- ind_xml(featureName = 'MMID', featureLevel = c(1:25),
#' newFieldName = 'MMID', purpose = 'dummy')
ind_xml <- function(featureName, featureLevel = c(0, 1), newFieldName = featureName, purpose = 'miss') {
LocalTransformations <- newXMLNode("LocalTransformations")
if (purpose == 'miss') {
DerivedField <- newXMLNode( "DerivedField", attrs = c( name = paste(purpose, newFieldName, sep = ""),
dataType = "double", optype = "continuous" ),
parent = LocalTransformations )
newXMLNode( "NormDiscrete", attrs = c( field = featureName, value = featureLevel[1] ),
parent = DerivedField )
} else {
for ( i in seq_along(featureLevel) ) {
DerivedField <- newXMLNode( "DerivedField", attrs = c( name = paste(purpose, newFieldName, "_", i, sep = ""),
dataType = "double", optype = "continuous" ),
parent = LocalTransformations )
newXMLNode( "NormDiscrete", attrs = c( field = featureName, value = featureLevel[i] ),
parent = DerivedField )
}
}
return(LocalTransformations)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.