I’d like to transform my array into a dataframe, with the column "Cluster" where there will be the numbers 5,4,2,1, … and "Trend" with numbers 1,2,3,4,…
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
cluster 5 4 2 1 2 4 1 2 2 5 1
What I expect :
Trend Cluster
1 5
2 4
3 2
4 1
...
>Solution :
With data.frame:
data.frame(Trend = seq_along(mat), t(mat))
# Trend cluster
# 1 1 5
# 2 2 4
# 3 3 2
Reproducible data:
mat <- t(c(5, 4, 2))
rownames(mat) <- "cluster"