将列表转换为R中的字符对象

时间:2013-08-06 11:12:11

标签: r

我想按如下方式转换列表:

    list(structure(c(16L, 17L, 71L, 87L, 113L, 120L, 127L, 128L, 
      144L, 177L, 207L, 213L), .Names = c("246653_at", "246897_at", 
      "251347_at", "252988_at", "255528_at", "256535_at", "257203_at", 
      "257582_at", "258807_at", "261509_at", "265050_at", "265672_at")))

进入角色对象:

         c("246653_at", "246897_at", "251347_at", "252988_at", "255528_at", 
         "256535_at", "257203_at", "257582_at", "258807_at", "261509_at", 
         "265050_at", "265672_at")

我尝试使用

    as.character(fin[1])

给了我

   [1] "c(16, 17, 71, 87, 113, 120, 127, 128, 144, 177, 207, 213)"

我提到this stack overflow post但无法解决。

2 个答案:

答案 0 :(得分:6)

如果您的对象是x

> names(unlist(x))
 [1] "246653_at" "246897_at" "251347_at" "252988_at" "255528_at" "256535_at"
 [7] "257203_at" "257582_at" "258807_at" "261509_at" "265050_at" "265672_at"

答案 1 :(得分:3)

或者只是......

names(fin[[1]])
 [1] "246653_at" "246897_at" "251347_at" "252988_at" "255528_at" "256535_at"
 [7] "257203_at" "257582_at" "258807_at" "261509_at" "265050_at" "265672_at"