{
  "id": 4198,
  "title": "R Code to read Matlab.csv files",
  "url": "/competitions/cause-effect-pairs/discussion/4198",
  "author_name": "",
  "post_date": "2013-04-04T07:40:11.237Z",
  "votes": null,
  "comment_count": 2,
  "views": 1963,
  "content": "<p>Hello&nbsp;</p>\r\n<p><span style=\"line-height:1.4em\">Can Anyone share R code to read <strong>CEdata_train_pairs.csv</strong> file which is given for Matlab such that&nbsp;</span></p>\r\n<p><span style=\"line-height:1.4em\">A &nbsp;&amp; B are considered as List with their elements as list and SampleID as factor&nbsp;</span></p>\r\n<p><span style=\"line-height:1.4em\">Thanks&nbsp;</span></p>",
  "messages": [
    {
      "id": "22139",
      "postDate": "04/04/2013 07:40:11",
      "content": "<p>Hello&nbsp;</p>\r\n<p><span style=\"line-height:1.4em\">Can Anyone share R code to read <strong>CEdata_train_pairs.csv</strong> file which is given for Matlab such that&nbsp;</span></p>\r\n<p><span style=\"line-height:1.4em\">A &nbsp;&amp; B are considered as List with their elements as list and SampleID as factor&nbsp;</span></p>\r\n<p><span style=\"line-height:1.4em\">Thanks&nbsp;</span></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "22156",
      "postDate": "04/04/2013 14:36:31",
      "content": "<p>See&nbsp;https://www.kaggle.com/c/cause-effect-pairs/forums/t/4144/cedata-text-more-r-friendly</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "22213",
      "postDate": "04/05/2013 03:34:19",
      "content": "<p>Here is the R code, I used. This reads the data into a list. The data strings start with a space, so the [-1] drop the first term (NA).</p>\r\n<p>&nbsp;</p>\r\n<pre>train.pairs.raw &lt;- read.csv(paste0(dir.path,'CEdata_train_pairs.csv'))\r\n\r\ntrain.pairs &lt;- lapply(1:nrow(train.pairs.raw), function(x) {\r\n  tmp.A &lt;- as.numeric(unlist(strsplit(as.character(train.pairs.raw[x,&quot;A&quot;]),&quot; &quot;)))[-1]\r\n  tmp.B &lt;- as.numeric(unlist(strsplit(as.character(train.pairs.raw[x,&quot;B&quot;]),&quot; &quot;)))[-1]\r\n  return(matrix(c(tmp.A,tmp.B),nrow=length(tmp.A),ncol=2))\r\n})\r\n</pre>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 22156,
      "author_name": "iguyon",
      "author_url": "",
      "post_date": "04/04/2013 14:36:31",
      "content": "<p>See&nbsp;https://www.kaggle.com/c/cause-effect-pairs/forums/t/4144/cedata-text-more-r-friendly</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 22213,
      "author_name": "nschneider",
      "author_url": "",
      "post_date": "04/05/2013 03:34:19",
      "content": "<p>Here is the R code, I used. This reads the data into a list. The data strings start with a space, so the [-1] drop the first term (NA).</p>\r\n<p>&nbsp;</p>\r\n<pre>train.pairs.raw &lt;- read.csv(paste0(dir.path,'CEdata_train_pairs.csv'))\r\n\r\ntrain.pairs &lt;- lapply(1:nrow(train.pairs.raw), function(x) {\r\n  tmp.A &lt;- as.numeric(unlist(strsplit(as.character(train.pairs.raw[x,&quot;A&quot;]),&quot; &quot;)))[-1]\r\n  tmp.B &lt;- as.numeric(unlist(strsplit(as.character(train.pairs.raw[x,&quot;B&quot;]),&quot; &quot;)))[-1]\r\n  return(matrix(c(tmp.A,tmp.B),nrow=length(tmp.A),ncol=2))\r\n})\r\n</pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "22139": "",
    "22156": "",
    "22213": ""
  },
  "source": "meta"
}