read.table函數是R語言中用于讀取文本文件數據到數據框的函數。下面是read.table函數的基本用法和參數解釋:
data <- read.table(file, header = FALSE, sep = "", quote = "\"", dec = ".", fill = FALSE, colClasses = NA, nrows = -1)
參數解釋:
示例:
data <- read.table("data.txt", header = TRUE, sep = "\t", dec = ",", colClasses = c("numeric", "character", "numeric"))
這個示例代碼會讀取"data.txt"文件,第一行是列名,字段之間用制表符分隔,小數點用逗號表示,第一列和第三列是數值型變量,第二列是字符型變量。