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"文件,第一行是列名,字段之间用制表符分隔,小数点用逗号表示,第一列和第三列是数值型变量,第二列是字符型变量。