Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
y <- read.csv("http://url_to _the_csv_file", header=F)

output of y

1            Date         Hostname        var1    var2     var3     var4      var5  
2   1/1/2012 12:00:00 AM servername         0   2.561700  4.9200  2.860000
3   1/2/2012 12:00:00 AM servername         0   2.602900  4.8400  2.930000
4   1/3/2012 12:00:00 AM servername         0   1.876300 15.1800  3.320000 16.244600
5   1/4/2012 12:00:00 AM servername         0   1.520400  4.8600  1.800000 16.661700
6   1/5/2012 12:00:00 AM servername         0   1.559500  5.3200  2.160000 12.969600
7   1/6/2012 12:00:00 AM servername         0   2.488800  9.0000  9.220000 14.497500
8   1/7/2012 12:00:00 AM servername         0   1.884200  3.0000  2.500000 14.017500

output of y[1]

                      V1
1            Date
2   1/1/2012 12:00:00 AM
3   1/2/2012 12:00:00 AM
4   1/3/2012 12:00:00 AM
5   1/4/2012 12:00:00 AM
6   1/5/2012 12:00:00 AM
7   1/6/2012 12:00:00 AM
8   1/7/2012 12:00:00 AM
9   1/8/2012 12:00:00 AM

I need to basically replace headers that are v1, v2 etc with the actual headers on row1

share|improve this question
1  
That link (getfile.pl?test.csv) doesn't seem to work. Could you maybe copy and paste the first few lines of the file into the question, or provide a working link? – nograpes Jan 13 '12 at 16:48
that ws just an example. the link is internal, you wont be able to get to it. The file format is like this: date, var1, var2, var3, var4, var5 then populated with some data. I can open the file, it is accurate – george willy Jan 13 '12 at 17:04
systems <- read.table("getfile.pl?test.csv";, header=FALSE, sep=","), I seem to get the file but know I have to deal with another row. If I print the contents of systems. this is how it looks: V1 V2 V3 V4 V5 StartDate, Server, uptime, load, memory – george willy Jan 13 '12 at 17:11

1 Answer

up vote 10 down vote accepted

Then tell read.table not to use row.names:

systems <- read.table("http://getfile.pl?test.csv", 
                      header=TRUE, sep=",", row.names=NULL)

and now your rows will simply be numbered.

Also look at read.csv which is a wrapper for read.table which already sets the sep=',' and header=TRUE arguments so that your call simplifies to

systems <- read.csv("http://getfile.pl?test.csv", row.names=NULL)
share|improve this answer
did you mean read.csv rather than read.table on your final code chunk? – Tyler Rinker Jan 13 '12 at 17:16
1  
I tried that before and it did not work. The first column now called "row.names" and the column names moved one cell further – george willy Jan 13 '12 at 17:17
@Tyler: yup, fixing now. Thanks! – Dirk Eddelbuettel Jan 13 '12 at 17:31
@Mike: That is the point of it as it avoids the error you complain about. Either fix your source data, or not it as row.names and the adjust the data afterwards. You can easily copy all but the first column to a new data.frame. – Dirk Eddelbuettel Jan 13 '12 at 17:32
1  
There is no need to go off this site. Please just follow common practice and edit and update your question. – Dirk Eddelbuettel Jan 13 '12 at 20:00
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.