R:将列表取消列出到数据框中的列 [英] R: Unlist list to columns in dataframe

查看:107
本文介绍了R:将列表取消列出到数据框中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由以下组成的数据框:

I have a data frame which is made of up:

Var1  Var2   Var3
a      b     nested list

嵌套列表=

 ####test:
           apple: a
           pear:   b
  ####test2:
             apple: a
             orange: c

是否有一种简单的方法可以将每行的v3中的嵌套列表转换成更多列,并使用列表元素名称作为变量名称以及每个单元格中的每个列表值? 例如

Is there a simple way to turn the nested list in v3 of each row into further columns, with the list element names as the variable names and each list value in each cell? e.g.

Var1 Var2 Var3        apple pear orange
a    b    nested list   a   b    NULL

推荐答案

也许您正在寻找tidyr::spread().如果没有可重现的示例,尝试其他方法总是很难的.

maybe you are looking for tidyr::spread(). It is anyways hard to try other things without a reproducible example.

这篇关于R:将列表取消列出到数据框中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆