R将带有标题列的文件读入data.frame

时间:2016-01-25 22:31:47

标签: r header dataframe multiple-columns

我读了一个文本文件如下:

a <- read.table("~/Desktop/seed_ant.dat", header = TRUE, skip = 3)

但是未正确识别列:

> a
1 Colony,Distance,Mass,Headwidth,Headwidth (mm),Worker class
2                             28,0,62.000,39.000,1.642,39-40
3                             28,0,53.000,39.000,1.642,39-40
4                             28,0,51.000,38.000,1.600,37-38

如何识别第1行中显示的列?

1 个答案:

答案 0 :(得分:0)

尝试:

 a <- read.csv("~/Desktop/seed_ant.dat", header = TRUE, skip = 3)

 a <- read.table("~/Desktop/seed_ant.dat", header = TRUE, skip = 3, sep = ",")

根据data.frame a的输出,您可能需要使用skip = 4来正确指示列。如果没有输入文件的前几行,很难说清楚。