2016-06-12 54 views
0

我需要在R之外導入數據集(csv-File),然後從R中的項目的Ruby端指定它(這將是用rinruby完成,並已工作)。從R字符串獲取包含csv的列表,其中包含csv

在我的R-Script中,我現在需要從該csv文件創建一個列表。

變量包含一個包含原始csv的轉義字符串。

data <- "\"\",\"futime\",\"fustat\",\"age\",\"resid.ds\",\"rx\",\"ecog.ps\"\n\"1\",59,1,72.3315,2,1,1\n\"2\",115,1,74.4932,2,1,1\n\"3\",156,1,66.4658,2,1,2\n\"4\",421,0,53.3644,2,2,1\n\"5\",431,1,50.3397,2,1,1\n\"6\",448,0,56.4301,1,1,2\n\"7\",464,1,56.937,2,2,2\n\"8\",475,1,59.8548,2,2,2\n\"9\",477,0,64.1753,2,1,1\n\"10\",563,1,55.1781,1,2,2\n\"11\",638,1,56.7562,1,1,2\n\"12\",744,0,50.1096,1,2,1\n\"13\",769,0,59.6301,2,2,2\n\"14\",770,0,57.0521,2,2,1\n\"15\",803,0,39.2712,1,1,1\n\"16\",855,0,43.1233,1,1,2\n\"17\",1040,0,38.8932,2,1,2\n\"18\",1106,0,44.6,1,1,1\n\"19\",1129,0,53.9068,1,2,1\n\"20\",1206,0,44.2055,2,2,1\n\"21\",1227,0,59.589,1,2,2\n\"22\",268,1,74.5041,2,1,2\n\"23\",329,1,43.137,2,1,1\n\"24\",353,1,63.2192,1,2,2\n\"25\",365,1,64.4247,2,2,1\n\"26\",377,0,58.3096,1,2,1" 

我想將其轉換爲R列表。

所以我的方法基本上是撥打read.csv(data_as_string),但不幸的是簽名是read.csv(file_where_data_lies)

這怎麼辦?

非常感謝!

+0

請參閱''read.csv''中的'text'參數 – bergant

+1

一般而言,您可以使用'textConnection',即'myfunc(file = textConnection(data))'。 – Therkel

+0

非常感謝你的工作! – Sebastian

回答

0

正如上面提到的Therkel,myfunc(file = textConnection(data))所做的正是我所要做的。謝謝!

相關問題