{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "e30b0ab6-c388-10a8-b058-6f8a020040a7"
      },
      "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",
        "\n",
        "library(ggplot2) # Data visualization\n",
        "library(readr) # CSV file I/O, e.g. the read_csv function\n",
        "library(data.table)\n",
        "library(Matrix)\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",
        "\n",
        "system(\"ls ../input\")\n",
        "\n",
        "# Any results you write to the current directory are saved as output."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "558bc23f-5d50-7502-2481-75b7851cdf88"
      },
      "outputs": [],
      "source": [
        "dt <- fread(\"../input/train_numeric.csv\",\n",
        "            drop = \"Id\",\n",
        "            nrows = 250000,\n",
        "            showProgress = F)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "07299e9a-a325-178a-4af3-2254df56e569"
      },
      "outputs": [],
      "source": [
        "Y  <- dt$Response\n",
        "dt[ , Response := NULL]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "21b925be-01b7-3d01-cfcd-f544d812905b"
      },
      "outputs": [],
      "source": [
        "for(col in names(dt)) set(dt, j = col, value = dt[[col]] + 2)\n",
        "for(col in names(dt)) set(dt, which(is.na(dt[[col]])), col, 0)\n",
        "\n",
        "X <- Matrix(as.matrix(dt), sparse = T)\n",
        "rm(dt)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "f3e510dc-4774-7e8d-e9ba-dfbc7b55293a"
      },
      "outputs": [],
      "source": [
        "summary(X)"
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "R",
      "language": "R",
      "name": "ir"
    },
    "language_info": {
      "codemirror_mode": "r",
      "file_extension": ".r",
      "mimetype": "text/x-r-source",
      "name": "R",
      "pygments_lexer": "r",
      "version": "3.3.1"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}