I have a list of elements called results1. Each element has a column and row names. This elements are vectors.
class(results1)
[1] "list"
> class(results1[[1]])
[1] "numeric"
is.vector(results1[[1]])
[1] TRUE
results1[[1]]
..a15.pdf ..a17.pdf ..a18.pdf ..a21.pdf
1.27679608 1.05090176 1.51820192 2.30296037
I want to convert each vector to a data frame of two columns, with the row names (denoted ..a15.pdf etc. above) being one of the columns. I can do it with a separate element/vector:
j<-as.data.frame(results1[[1]])
j<-cbind(j,names=rownames(j))
rownames(j) <- c()
But I can not achieve it for the entire list. I tried
results1<-lapply(results1, function(x)cbind(x, names=rownames(x)))
I can see two columns
results1[[1]]
x
..a15.pdf 1.27679608
..a17.pdf 1.05090176
..a18.pdf 1.51820192
But apparently this does not create a data frame.
is.data.frame(results1[[1]])
[1] FALSE
And as I understand it the ..15pdf is not a column
results1[[1]][,1]
..a15.pdf ..a17.pdf ..a18.pdf ..a21.pdf
1.27679608 1.05090176 1.51820192 2.30296037
I tried then to convert my vectors to data frames first:
results1<-lapply(results1, function(x)as.data.frame(x[1]))
results1<-lapply(results1, function(x){as.data.frame(x[1])})
But it did not work. As stated above, I'd like to convert rownames from each vector to a column and delete them. The output should be a list of data frames, each df having two columns. The rownames column should be named 'names', if you need a name. Thanks. Here is dput for the first two vectors of my list
dput(results1[c(1,2)])
list(c(..a15.pdf = 1.27679607834331, ..a17.pdf = 1.05090175857491,
..a18.pdf = 1.51820192474905, ..a21.pdf = 2.30296037386815, ..a2TTT.pdf = 1.48568731934637,
..a5.pdf = 0.493713103224402, ..B11.pdf = 1.02705905465749, ..B12.pdf = 0.999747360884078,
..B13.pdf = 2.40828101927852, ..B22.pdf = 0.695152132033603,
..B24.pdf = 2.1436001615064, ..B4.pdf = 2.25444037842867, ..B7.pdf = 0.909773940025014,
..B8.pdf = 1.14837173756827, `..cw10-1.pdf` = -1.36323271003293,
`..cw15-1TTT.pdf` = 0.341428535787024, `..cw17-1.pdf` = -0.786878348480425,
..cw18.pdf = 0.793720472787986, ..cw3.pdf = -1.57831038567642,
..cw4.pdf = 0.277733503122777, ..cw7_1TTT.pdf = -0.0364645818969112,
`..cw13-1.pdf` = -18.336668416705), c(..a15.pdf = 2.096687569578,
..a17.pdf = 2.19826038300833, ..a18.pdf = 1.91814204277357, ..a21.pdf = 0.801448541154512,
..a2TTT.pdf = 2.16169560949165, ..a5.pdf = 1.48585130705963,
..B11.pdf = 0.95126061691997, ..B12.pdf = 1.93116618236938, ..B13.pdf = 1.92555316191766,
..B22.pdf = 1.00560861920225, ..B24.pdf = 2.91129684208931, ..B4.pdf = 2.75687804718002,
..B7.pdf = 1.31164431967781, ..B8.pdf = 2.22449059765255, `..cw10-1.pdf` = -1.22629519335285,
`..cw15-1TTT.pdf` = 1.31168579553008, `..cw17-1.pdf` = -17.5786422399896,
..cw18.pdf = 1.25323523754693, ..cw3.pdf = -0.754445550651364,
..cw4.pdf = 0.555577381430987, ..cw7_1TTT.pdf = 0.577850999404076,
`..cw13-1.pdf` = -34.2662973287062))