cbind子集在r中的一列中

时间:2014-11-27 08:07:18

标签: r subset cbind

我已经创建了一个数据帧的子集,我用它来计算。我现在留下了多个子集,我想将它们组合成一列。子集看起来像这样:

> E
$`1`
 [1] "AAAaaa" "TTTaaa" "CCCaaa" "GGGaaa" "AAAttt" "TTTttt" "CCCttt" "GGGttt"
 [9] "AAAccc" "TTTccc" "CCCccc" "GGGccc" "AAAggg" "TTTggg" "CCCggg" "GGGggg"

$`2`
 [1] "ATAata" "TATata" "CGCata" "GCGata" "BBBata" "ATAtat" "TATtat" "CGCtat"
 [9] "GCGtat" "BBBtat" "ATAcgc" "TATcgc" "CGCcgc" "GCGcgc" "BBBcgc" "ATAgcg"
[17] "TATgcg" "CGCgcg" "GCGgcg" "BBBgcg" "ATAbbb" "TATbbb" "CGCbbb" "GCGbbb"
[25] "BBBbbb"

我试过了:

A=vector()
cbind(A,ExonJunction,deparse.level = 1)
A

但这让我不知道

  E
1 Character,16
2 Character,25

我想要一列中的字符列表。我该怎么做?

3 个答案:

答案 0 :(得分:2)

还可以尝试recursive函数中的c参数,类似

c(E, recursive = TRUE, use.names = FALSE)
#  [1] "AAAaaa" "TTTaaa" "CCCaaa" "GGGaaa" "AAAttt" "TTTttt" "CCCttt" "GGGttt" "AAAccc" "TTTccc" "CCCccc" "GGGccc" "AAAggg" "TTTggg" "CCCggg" "GGGggg" "ATAata"
# [18] "TATata" "CGCata" "GCGata" "BBBata" "ATAtat" "TATtat" "CGCtat" "GCGtat" "BBBtat" "ATAcgc" "TATcgc" "CGCcgc" "GCGcgc" "BBBcgc" "ATAgcg" "TATgcg" "CGCgcg"
# [35] "GCGgcg" "BBBgcg" "ATAbbb" "TATbbb" "CGCbbb" "GCGbbb" "BBBbbb"

或者,如果您希望将其作为数据框中的列,可以尝试

df <- data.frame(Res = c(E, recursive = TRUE))

答案 1 :(得分:1)

您可unlist list并使用data.frame创建单个列数据框

dat <- data.frame(Col1=unlist(E, use.names=FALSE), stringsAsFactors=FALSE)

数据

E <-  structure(list(`1` = c("AAAaaa", "TTTaaa", "CCCaaa", "GGGaaa", 
"AAAttt", "TTTttt", "CCCttt", "GGGttt", "AAAccc", "TTTccc", "CCCccc", 
"GGGccc", "AAAggg", "TTTggg", "CCCggg", "GGGggg"), `2` = c("ATAata", 
"TATata", "CGCata", "GCGata", "BBBata", "ATAtat", "TATtat", "CGCtat", 
"GCGtat", "BBBtat", "ATAcgc", "TATcgc", "CGCcgc", "GCGcgc", "BBBcgc", 
"ATAgcg", "TATgcg", "CGCgcg", "GCGgcg", "BBBgcg", "ATAbbb", "TATbbb", 
"CGCbbb", "GCGbbb", "BBBbbb")), .Names = c("1", "2"))

答案 2 :(得分:1)

您也可以像这样使用stack(假如您正在处理命名列表,就像您一样):

stack(E)

一个很好的功能是名称成为“ind”列,因此该过程很容易逆转。

head(stack(E))
#   values ind
# 1 AAAaaa   1
# 2 TTTaaa   1
# 3 CCCaaa   1
# 4 GGGaaa   1
# 5 AAAttt   1
# 6 TTTttt   1
tail(stack(E))
#    values ind
# 36 BBBgcg   2
# 37 ATAbbb   2
# 38 TATbbb   2
# 39 CGCbbb   2
# 40 GCGbbb   2
# 41 BBBbbb   2