与data.frame不等长的字符向量列表 [英] list of character vectors of unequal length to data.frame

查看:114
本文介绍了与data.frame不等长的字符向量列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的命名列表:

I have a named list that looks like this:

> head(pathways)
$<NA>
NULL
$`2`
[1] "hsa04610"
$`9`
[1] "hsa00232" "hsa00983" "hsa01100"
$`10`
[1] "hsa00232" "hsa00983" "hsa01100"
$<NA>
NULL
$<NA>
NULL

更早地描述它.每个列表的名称是一个ID号,而作为列表元素的字符向量的每个元素的条目是另一个ID号.我可以使用is.na()轻松过滤出$<NA>条目,但随后我想更改其余内容,使其看起来像:

To describe it more formerly. The name of each list is an id number, and the entries of each element of the character vector that are elements of the list is another id number. I can filter out the $<NA> entries easily with is.na(), but then I want to change the rest so it would look like:

id   another_id
2    hsa04610   
9    hsa00232   
9    hsa00983   
9    hsa01100   
10   hsa00232  
10   hsa00983
10   hsa01100


> dput(test)
structure(list(`NA` = NULL, `2` = "hsa04610", `9` = c("hsa00232", 
"hsa00983", "hsa01100"), `10` = c("hsa00232", "hsa00983", "hsa01100"
), `NA` = NULL, `NA` = NULL), .Names = c(NA, "2", "9", "10", 
NA, NA))

有什么想法吗?

推荐答案

所以我找到了另一个可行的答案.

So I found another answer that seems to work.

stack(pathways)

这似乎太简单了,但是哦.

This seems too easy, but oh well.

这篇关于与data.frame不等长的字符向量列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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