3
我正在學習R,並被要求使用pi2000數據集,可在simpleR庫(http://www.math.csi.cuny.edu/Statistics/R/simpleR/index.html/simpleR.R)處獲得。然後我下載了這個文件。我如何將它導入命令行?從R文件導入東西
我正在學習R,並被要求使用pi2000數據集,可在simpleR庫(http://www.math.csi.cuny.edu/Statistics/R/simpleR/index.html/simpleR.R)處獲得。然後我下載了這個文件。我如何將它導入命令行?從R文件導入東西
使用source
功能:
> source("http://www.math.csi.cuny.edu/Statistics/R/simpleR/index.html/simpleR.R")
然後可以訪問其中定義的變量:
> vacation
[1] 23 12 10 34 25 16 27 18 28 13 14 20 8 21 23 33 30 13 16 14 38 19 6 11 15 21 10
[28] 39 42 25 12 17 19 26 20
獲得更多信息,類型?source
到R端子。
你的意思是將函數加載到R中?如果是這樣,請使用source()
:
source("http://www.math.csi.cuny.edu/Statistics/R/simpleR/index.html/simpleR.R")
謝謝亞歷克斯! :) – lucasn 2012-01-03 05:26:17
@亞歷布朗謝謝!它只是加載r文件的方法嗎? – verystrongjoe 2015-10-15 06:07:58
@verystrongjoe,不,當然不是,因爲R有'eval',它有'library',所以有很多方法可以做到。但是,這是R設計人員爲您創建的將R文件內嵌到第二個文件的方式。另請參閱'?source'以瞭解可用的選項。 – 2015-10-23 18:37:40