Karnage2015
Karnage2015

Reputation: 13

How to use the column names already in text file in R

Suppose I have a text file, data.txt, containing

A  B  C  D
1  2  3  4 
5  6  7  8 

Using read.table, I get:

> d = read.table('data.txt')
> d
    V1  V2  V3 V4
1   A   B   C  D
2   1   2   3  4
3   5   6   7  8

How do I make it so that instead of V1 V2 V3 V4 appearing, I get the column names that are in the text file? In other words, I would like to have this:

> d
    A   B   C  D
1   1   2   3  4
2   5   6   7  8

Upvotes: 0

Views: 2511

Answers (1)

Martijn vd Voort
Martijn vd Voort

Reputation: 366

you could use d <- read.table('data.txt', header=T)

Upvotes: 3

Related Questions