13

I have a csv with column name in first row of the file, and column name in first column of the file, like this:

ColName1 ColName2 ... ColNameN
RowName1 ..
RowName2 ..
RowNameN .. 

If I use this command: read.csv("/Users/MNeptune/Documents/workspace R/simulatedProfiles.csv", header=TRUE)

I read correctly only columns name but not row name. What i can do to read row name?

Neptune
  • 607
  • 2
  • 8
  • 19

2 Answers2

28

Try read.csv("filename.csv", row.names = 1, header= TRUE).

Chris
  • 1,248
  • 4
  • 17
  • 25
  • row.names is available only in read.table as per this [doc](http://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html) – Gagan Nov 04 '16 at 08:20
  • But its working in read.csv also so read.csv is add on to read.table. – Gagan Nov 04 '16 at 08:24
7

There is a row.names option to read.csv (inherited from read.table) in which you can specify the column in the file to be used as row.names.

read.csv("/path/to/file", header=TRUE, row.names=1)
asb
  • 4,392
  • 1
  • 20
  • 30