Read TXT Files in R: Complete Guide
In R language, you can use the read.table() function to read a txt file. The specific method is as follows:
# 读取txt文件
data <- read.table("文件路径/文件名.txt", header = TRUE, sep = "\t")
# 查看数据结构
str(data)
# 查看数据前几行
head(data)
The path and filename of the txt file to be read is “file path/file name.txt”, setting header = TRUE indicates that the first row is the column name, and sep = “\t” specifies that the data is tab-separated. After reading the data, you can use the str() function to view the data structure and the head() function to view the first few rows.