{"cells":[
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages\n# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats\n# For example, here's several helpful packages to load in \n\nlibrary(ggplot2) # Data visualization\nlibrary(readr) # CSV file I/O, e.g. the read_csv function\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nsystem(\"ls ../input\")\n### Exloratory Data Analysis\n## Load the data\nprod.tbl<-read.csv(\"../input/producto_tabla.csv\",header = TRUE, sep = \",\")\ntown.tbl<-read.csv(\"../input/town_state.csv\",header = TRUE, sep = \",\")\nclient.tbl<-read.csv(\"../input/cliente_tabla.csv\",header = TRUE, sep = \",\")\n#sample_submis.tbl<-read.csv(\"../input/sample_submission.csv\",header = TRUE, sep = \",\")\n#train.tbl<-read.csv(\"../input/train.csv\",header = TRUE, sep = \",\")\n#test.tbl<-read.csv(\"../input/test.csv\",header = TRUE, sep = \",\")"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "## Get the data dimensions\ndim(prod.tbl)\nprint (\"Product Table dimension\")\ndim(client.tbl)\nprint (\"Client Table dimension\")\ndim(town.tbl)\nprint (\"Town Table dimension\")"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "## Get the data structure\nprint (\"Product Table structure\")\nstr(prod.tbl)\nprint (\"Client Table structure\")\nstr(client.tbl)\nprint (\"Town Table structure\")\nstr(town.tbl)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "## Joining the different tables together\nprint(\"Joining Product and Client Table\")\nprod_client_tbl<-merge(prod.tbl,client.tbl,by.x=\"Producto_ID\",by.y=\"Cliente_ID\")\nhead(prod_client_tbl)\nprint (\"Structure of Product and Client Table\")\nstr(prod_client_tbl)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": "print(\"Joining Product-Client table with Town table\")\nprod_client_town_tbl<-merge(prod_client_tbl,town.tbl,by.x=\"Producto_ID\",by.y=\"Agencia_ID\")\nhead(prod_client_town_tbl)\nprint (\"Structure of Product-Client-Town Table\")\nstr(prod_client_town_tbl)"
 },
 {
  "cell_type": "code",
  "execution_count": null,
  "metadata": {
   "collapsed": false
  },
  "outputs": [],
  "source": ""
 }
],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"}}, "nbformat": 4, "nbformat_minor": 0}