How to convert array to data.table in R and back?

前端 未结 3 692
自闭症患者
自闭症患者 2021-01-20 06:19

is this the most straightforward way to convert an array into a data.table?

require(data.table)
require(ggplot2)

# this returns a data.tabl         


        
3条回答
  •  误落风尘
    2021-01-20 06:52

    convert the data.table back into the original array

    Here a quick and dirty solution

    DT2 = as.data.table(aaa)
    aaa2= array(dim = dim(aaa))
    invisible(DT2[, aaa2[V1, V2, V3] <<- value, .(V1,V2,V3)])
    all.equal(aaa,aaa2) # TRUE
    

提交回复
热议问题