美文网首页
py字典转R语言的list

py字典转R语言的list

作者: 倪桦 | 来源:发表于2022-05-09 22:26 被阅读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
    

    相关文章

      网友评论

          本文标题:py字典转R语言的list

          本文链接:https://www.haomeiwen.com/subject/wyskurtx.html