Reputation: 89
I have a data frame as follows below. I would like to use the values in the columns of the first row as the column names. As the columns are 275 in total, they are too many to use the simple way of assignment e.g. df <- c("a","b")
Appreciate your kind help.
> dim(db)
[1] 10 275
> db[1:5,1:5]
V4 V5 V6 V7 V8
1 1352.9400 1357.5300 1361.7500 1365.9800 1370.2000
2 0.0662 0.0882 0.1125 0.1409 0.1768
3 0.0659 0.0879 0.1122 0.1406 0.1765
4 0.0663 0.0884 0.1127 0.1411 0.1770
5 0.0622 0.0843 0.1086 0.1369 0.1728
>
thanks,
--ihsanna
Upvotes: 0
Views: 442
Reputation: 724
Did you get this with read.csv or read.table? Either have an option for header = T to read in with the first row as column names if not the below should work.
names(db) <- db[1,]
If you want to delete the first row use:
db <- db[-1,]
Upvotes: 2