Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Read csv with row and column name

Tags:

r

csv

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?

like image 530
Neptune Avatar asked Jun 11 '14 09:06

Neptune


People also ask

What is the difference between read csv and Read_csv in R?

The read_csv function imports data into R as a tibble, while read. csv imports a regular old R data frame instead.

What is header true in R?

• The header = TRUE argument tells R that the first row of your. file contains the variable names.


2 Answers

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

like image 84
Chris Avatar answered Sep 18 '22 08:09

Chris


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)
like image 33
asb Avatar answered Sep 19 '22 08:09

asb