user3081773
user3081773

Reputation: 1

how to de-merge column name and data in 1st row when importing a .csv file?

Code:

data <- read.csv("./data.csv",header=T)
data

Output:

   X224786   X578    X871   X9719
1   230034    546     969   10262
2   236562    599     845   10120

Expected Output:

     A    B   C         D
224786  578 871  9719
230034  546 969 10262
236562  599 845 10120

Upvotes: 0

Views: 57

Answers (2)

BorisKovarsky
BorisKovarsky

Reputation: 63

Obviously, your *.csv file has no header line. So, try:

data <- read.csv("./data.csv", header=F)
names(data) <- c("A","B","C","D")

Upvotes: 2

Neal Fultz
Neal Fultz

Reputation: 9696

Try read.table instead of read.csv. read.csv requires commas between each field.

Upvotes: 0

Related Questions