In base R :
result <- data.frame(row = rownames(df1),
name = rep(names(df1), each = ncol(df1)),
value = unlist(df1), row.names = NULL)
result
# row name value
#1 n1 c1 0.1
#2 n2 c1 0.4
#3 n3 c1 0.7
#4 n1 c2 0.2
#5 n2 c2 0.5
#6 n3 c2 0.8
#7 n1 c3 0.3
#8 n2 c3 0.6
#9 n3 c3 0.9
Or using tidyr
s pivot_longer
:
library(dplyr)
library(tidyr)
df1 %>% rownames_to_column('row') %>% pivot_longer(cols = -row)
data
df1 <- structure(list(c1 = c(0.1, 0.4, 0.7), c2 = c(0.2, 0.5, 0.8),
c3 = c(0.3, 0.6, 0.9)), class = "data.frame",
row.names = c("n1", "n2", "n3"))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…