Enter the name of the variables in the first row of the dataframe

-1

I want to enter the variable name as the first line of my datafrane. For example:

   X11.3116555055603 X16.8234904296696
1           14.79609          10.37313
2           10.02141          16.38942
3           12.10137          18.75196
4           14.29997          15.90409
5           15.07731          13.77788
6           19.33323          19.92858
7           13.41967          17.74106
8           11.96044          19.09498
9           19.13904          16.15948

But I want to:

1           X11.3117          X16.8235
2           14.79609          10.37313
3           10.02141          16.38942
4           12.10137          18.75196
5           14.29997          15.90409
6           15.07731          13.77788
7           19.33323          19.92858
8           13.41967          17.74106
9           11.96044          19.09498
10          19.13904          16.15948

dput :

data=structure(list(X11.3116555055603 = c(14.7960854065605, 
10.0214068288915, 
                                      12.1013720962219, 14.299969333224, 
15.077308237087, 19.3332333257422, 
                                      13.4196697315201, 11.9604384386912, 
19.1390363522805), X16.8234904296696 = c(10.3731271764264, 

16.3894248008728, 18.7519607762806, 15.9040869213641, 13.7778785359114, 

19.9285765457898, 17.7410648972727, 19.0949787106365, 16.1594827705994
                                      )), class = "data.frame", row.names = 
2:10)
    
asked by anonymous 21.09.2018 / 16:28

1 answer

1

It probably has a more practical way, but it follows code that returns the structure you expect:

data[nrow(data)+1,] <- names(data)
data <- data[c(nrow(data), 1:(nrow(data)-1)),]
rownames(data) <- 1:nrow(data)
names(data) <- NULL

First I add the column names as the last line of data.frame ; then I reorder the data so that the name is first line; I change the name of the lines and finally "delete" the name of the columns.

    
21.09.2018 / 17:47