BaconDoggie
BaconDoggie

Reputation: 153

reading a csv file in r where the header have commas

In excel when opening the csv, you can see the column names separated by commas e.g

 rabbit,8am,carrot          fox,12am,fish(salmon)
            1                            2
            4                            4
            2                            3
            .                            .
            .                            .
            .                            .

When I read this type of file in R, then it reads it as

 rabbit..8am.carrot          fox...12am..fish.salmon..
            1                            2
            4                            4
            2                            3
            .                            .
            .                            .
            .                            .

Is there any way to read the file so I can get the comas back. I am trying to make variables from the column names by splitting on the commas.

Upvotes: 1

Views: 396

Answers (1)

Jilber Urbina
Jilber Urbina

Reputation: 61154

Set check.names = FALSE when using read.table. See ?read.table

> foo <- read.table(text="rabbit,8am,carrot          fox,12am,fish(salmon)
              1                            2
              4                            4", header=TRUE, check.names = FALSE)
> foo
  rabbit,8am,carrot fox,12am,fish(salmon)
1                 1                     2
2                 4                     4

Upvotes: 1

Related Questions