Skip to content

Instantly share code, notes, and snippets.

@petermreid
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermreid/1a41a151da199e52d8d5 to your computer and use it in GitHub Desktop.
Save petermreid/1a41a151da199e52d8d5 to your computer and use it in GitHub Desktop.
Titanic
ut ports to variables
dataset1 <- maml.mapInputPort(1) # class: data.frame
#Create the AgeGroup bins
dataset1$AgeGroup <- ifelse(is.na(dataset1$Age), NA, ifelse(dataset1$Age < 2, "Baby", ifelse(dataset1$Age < 16, "Young", ifelse(dataset1$Age > 60, "Old", "Middle"))))
#Parse the Name for Title
getTitle <- function(name) {return (sub(" ", "", unlist(strsplit(name, "[,.]"))[2]))}
dataset1$Title=apply(matrix(dataset1$Name),1,getTitle)
#Aggregate the family memebrs together
dataset1$FamilyMembers=dataset1$SibSp+dataset1$Parch
#Have another go at AgeGroup to fill in the blanks
dataset1$AgeGroup <- ifelse(is.na(dataset1$Age), ifelse((dataset1$Title=="Master"|dataset1$Title=="Miss"), "Young","Middle") ,dataset1$AgeGroup)
# Select data.frame to be sent to the output Dataset port
maml.mapOutputPort("dataset1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment