How to get this data structure in R?

后端 未结 2 1315
轮回少年
轮回少年 2020-12-11 13:28

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

2条回答
  •  鱼传尺愫
    2020-12-11 14:02

    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'))[]
    

提交回复
热议问题