py字典转R语言的list

2022-05-09  本文已影响0人  倪桦
dict_py= {"A":[4, 2, 5, 3], "B":[5, 2], "C":[6, 3, 2, 5, 5]}
···{'A': [4, 2, 5, 3], 'B': [5, 2], 'C': [6, 3, 2, 5, 5]}
import rpy2.robjects as robjects
x = robjects.ListVector( [(str(e), dict_py[e]) for i, e in enumerate(dict_py)] )
r = robjects.r('''
           func <- function(List){
               list.r <- list()
               for (i in names(List)) {
                    list.r[[i]] <-unlist(List[[i]]) 
                }
                print(list.r)
           }
           ''')
r(x)
···$A
···[1] 4 2 5 3

···$B
···[1] 5 2

···$C
···[1] 6 3 2 5 5
上一篇下一篇

猜你喜欢

热点阅读