2017-07-12 16 views
0

私はリストとヌルデータフレーム(api fun!)の醜いリストを持っています。私が欲しいのは、name要素のベクトルです。この場合、ベクトルは長さが13で、NAsではdata frame with 0 columns and 0 rowsとなります。リストと空のデータフレームのリストから要素を抽出

myList <- list(structure(list(uuid = "x1", 
    name = "thanks"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(uuid = "x2", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
    structure(list(uuid = "x3", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(uuid = "x4", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(uuid = "x5", 
     name = "enrolled"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(uuid = "x6", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
    structure(list(uuid = "x7", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(), .Names = character(0), row.names = integer(0), class = "data.frame"), 
    structure(list(uuid = "x8", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(uuid = "x9", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L), 
    structure(list(uuid = "x10", 
     name = "team"), .Names = c("uuid", "name"), class = "data.frame", row.names = 1L)) 

所望の出力:

"thanks" "team" NA "team" "team" "enrolled" "team" NA "team" NA "team" "team" "team" 
+0

'非公開に(lapply(はmyList、機能(a)からc($名、NA)[1 + is.null($ name)])) ' –

答えて

1

多分それはあなたのために働く:

sapply(myList, function(x){ 
    if(all(dim(x) == c(0,0))){ 
     x <- NA 
    } else x <- x$name 
}) 
+0

が私のために働きます。 ! –

関連する問題