開始使用免費開始

read_tsv

當你使用 read_csv() 輕鬆讀取 CSV 檔時,也可以使用 read_tsv() 輕鬆讀取 TSV 檔。TSV 是以定位字元(tab)分隔的值。

這次馬鈴薯資料是以定位字元分隔的檔案提供;potatoes.txtview)已放在你的工作空間中。與 potatoes.csv 不同,這個檔案的第一列並沒有包含欄位名稱。

你有一個向量 properties,可以手動指定這些欄位名稱。

本練習屬於課程

R 資料匯入入門

檢視課程

練習說明

  • 使用 read_tsv()potatoes.txt 匯入馬鈴薯資料,並將其儲存為資料框 potatoes。除了檔案路徑外,你還需要指定 col_names 引數;可以使用向量 properties
  • potatoes 呼叫 head(),顯示資料集的前幾筆觀察值。

動手互動練習

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

# Column names
properties <- c("area", "temp", "size", "storage", "method",
                "texture", "flavor", "moistness")

# Import potatoes.txt: potatoes
potatoes <- ___

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