Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read.csv row.names

Tags:

r

read.csv

I'm trying to read a column oriented csv file into R as a data frame.

the first line of the file is like so:

sDATE, sTIME,iGPS_ALT, ...

and then each additional line is a measurement:

4/10/2011,2:15,78, ...

when I try to read this into R, via

d = read.csv('filename')

I get a duplicate row.names error since R thinks that the first column of the data is the row names, and since all of the measurements were taken on the same day, the values in the first column do not change.

If I put in row.names = NULL into the read.csv call, I get an extraneous column d$row.names which corresponds to the sDATE column, and everything is "shifted" one column down, so d$sDATE would have 2:15 in it, not 4/10/2011 as needed.

If I open my csv in excel, do nothing and then save it, everything's cool. I have to process hundreds of these, so manually saving in excel is not something I want. If there's something programmatically I can do to preprocess these csv's in python or otherwise, that would be great.

like image 480
nimish Avatar asked Jul 06 '11 11:07

nimish


People also ask

What does row names 1 do in R?

Assigning the second argument, row. names , to be 1 indicates that the data file has row names, and which column number they are stored in.

How do you give a column name while reading a CSV file?

While reading the CSV file, you can rename the column headers by using the names parameter. The names parameter takes the list of names of the column header. To avoid the old header being inferred as a row for the data frame, you can provide the header parameter which will override the old header names with new names.

Can Read table read CSV?

The read. table() method is used to read data from files. These can be . csv files or .

What is names in PD Read_csv?

names parameter in read_csv function is used to define column names. If you pass extra name in this list, it will add another new column with that name with NaN values. header=None is used to trim column names is already exists in CSV file.


1 Answers

read.csv only assumes there are any row names if there are less values in the header than in the other rows. So somehow you are either missing a column name or have an extra column you don't want.

like image 114
wkmor1 Avatar answered Sep 29 '22 01:09

wkmor1