I am trying to find Wanted data structure from the current data structure. I know the schematics of the expected data structure partially. The wanted data structure includ
We can use tidyverse
library(tidyverse)
dat.m %>%
as.data.frame() %>%
rownames_to_column('Vars') %>%
rename(M1 = V1, M2 = V2)
# Vars M1 M2
#1 ave_max 150 61
#2 ave 60 0
#3 lepo 41 0
If we need to use data.table
library(data.table)
setnames(setDT(as.data.frame(dat.m), keep.rownames = TRUE), c('Vars', 'M1', 'M2'))[]