開始使用免費開始

read.table

如果你要處理更特殊的平面檔格式,建議使用 read.table()。這是最基礎的匯入函式,你可以在其中指定很多不同的引數。與 read.csv()read.delim() 不同,header 引數的預設值是 FALSE,而 sep 的預設值是 ""

還是交給你決定!資料仍然是 hotdogs.txt([檢視](http://s3.amazonaws.com/assets.datacamp.com/production/course_1477/datasets/hotdogs.txt))。它的第一列沒有欄位名稱,而且欄位分隔符是定位字元(tab)。不過這次,檔案位在你目前工作目錄底下的 data 資料夾中。代表此檔案位置的變數 path 已經幫你建立好了。

本練習屬於課程

R 資料匯入入門

檢視課程

練習說明

  • 完成 read.table() 的呼叫,載入位於 path 的「tab 分隔」檔案。
  • hotdogs 呼叫 head();這會印出資料框前 6 筆觀測值。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Path to the hotdogs.txt file: path
path <- file.path("data", "hotdogs.txt")

# Import the hotdogs.txt file: hotdogs
hotdogs <- read.table(___, 
                      sep = ___, 
                      col.names = c("type", "calories", "sodium"))

# Call head() on hotdogs
___
編輯並執行程式碼