我在R中使用gmailr
软件包。
其中一个输出提供了我在gmail帐户中的可用文件夹的列表。
test<-labels(user_id = "me")
test$labels[[1]]
$id
[1] "CATEGORY_PERSONAL"
$name
[1] "CATEGORY_PERSONAL"
$type
[1] "system"
如何从test
的输出中,通过在test
列表中搜索名称“ Submissions”来提取ID?
以下是我的报告:
structure(list(labels = list(structure(list(id = "CATEGORY_PERSONAL",
name = "CATEGORY_PERSONAL", type = "system"), .Names = c("id",
"name", "type")), structure(list(id = "Label_4332171194581770179",
name = "Weather Data/2018 Data/Individual confirmation",
type = "user"), .Names = c("id", "name", "type")), structure(list(
id = "Label_1", name = "Personal", messageListVisibility = "show",
labelListVisibility = "labelHide", type = "user"), .Names = c("id",
"name", "messageListVisibility", "labelListVisibility", "type"
)), structure(list(id = "CATEGORY_SOCIAL", name = "CATEGORY_SOCIAL",
messageListVisibility = "hide", labelListVisibility = "labelHide",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "Label_6629457537668286728",
name = "Submissions", messageListVisibility = "show", labelListVisibility = "labelShow",
type = "user"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "Label_7658051581964161134",
name = "Weather Data/2018 Data/Individual Complete", type = "user"), .Names = c("id",
"name", "type")), structure(list(id = "CATEGORY_FORUMS", name = "CATEGORY_FORUMS",
messageListVisibility = "hide", labelListVisibility = "labelHide",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "Label_2850739645999054837",
name = "Weather Data/2017 Data", type = "user"), .Names = c("id",
"name", "type")), structure(list(id = "Label_2", name = "Receipts",
messageListVisibility = "hide", labelListVisibility = "labelShow",
type = "user"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "Label_1014871627782562484",
name = "Weather Data/2017 Data/Individual complete", type = "user"), .Names = c("id",
"name", "type")), structure(list(id = "Label_4", name = "Work",
messageListVisibility = "hide", labelListVisibility = "labelShow",
type = "user"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "Label_22371230351786854",
name = "Weather Data/2018 Data", type = "user"), .Names = c("id",
"name", "type")), structure(list(id = "IMPORTANT", name = "IMPORTANT",
messageListVisibility = "hide", labelListVisibility = "labelHide",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "Label_6142857437130093186",
name = "Weather Data/2017 Data/individual confirmation emails",
type = "user"), .Names = c("id", "name", "type")), structure(list(
id = "Label_3", name = "Travel", messageListVisibility = "show",
labelListVisibility = "labelHide", type = "user"), .Names = c("id",
"name", "messageListVisibility", "labelListVisibility", "type"
)), structure(list(id = "CATEGORY_UPDATES", name = "CATEGORY_UPDATES",
messageListVisibility = "hide", labelListVisibility = "labelHide",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "CHAT",
name = "CHAT", messageListVisibility = "hide", labelListVisibility = "labelShow",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "Label_4351557222970420897",
name = "Weather Data", messageListVisibility = "show", labelListVisibility = "labelShow",
type = "user"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "SENT",
name = "SENT", messageListVisibility = "hide", labelListVisibility = "labelShow",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "INBOX",
name = "INBOX", messageListVisibility = "hide", labelListVisibility = "labelShow",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "TRASH",
name = "TRASH", messageListVisibility = "hide", labelListVisibility = "labelShow",
type = "system"), .Names = c("id", "name", "messageListVisibility",
"labelListVisibility", "type")), structure(list(id = "CATEGORY_PROMOTIONS",
name = "CATEGORY_PROMOTIONS", messageListVisibility = "hide",
labelListVisibility = "labelHide", type = "system"), .Names = c("id",
"name", "messageListVisibility", "labelListVisibility", "type"
)), structure(list(id = "DRAFT", name = "DRAFT", messageListVisibility = "hide",
labelListVisibility = "labelShow", type = "system"), .Names = c("id",
"name", "messageListVisibility", "labelListVisibility", "type"
)), structure(list(id = "SPAM", name = "SPAM", messageListVisibility = "hide",
labelListVisibility = "labelHide", type = "system"), .Names = c("id",
"name", "messageListVisibility", "labelListVisibility", "type"
)), structure(list(id = "STARRED", name = "STARRED", messageListVisibility = "hide",
labelListVisibility = "labelHide", type = "system"), .Names = c("id",
"name", "messageListVisibility", "labelListVisibility", "type"
)), structure(list(id = "UNREAD", name = "UNREAD", type = "system"), .Names = c("id",
"name", "type")), structure(list(id = "Label_2707339598948997574",
name = "Weather Data/2018 Data/Complete", type = "user"), .Names = c("id",
"name", "type")), structure(list(id = "Label_8600983624680593897",
name = "Weather Data/2017 Data/Complete", type = "user"), .Names = c("id",
"name", "type")))), .Names = "labels")
答案 0 :(得分:1)
我们可以使用双@(t,y)dxdt returns a vector of length 69, but the length of initial conditions vector is 1. The vector returned by @(t,y)dxdt and the initial conditions vector must have the same number of elements.
:
sapply
其中
sapply(test[sapply(test, `[[`, "name") == "Submissions"], `[[`, "id")
# [1] "Label_6629457537668286728"
找到“提交”的情况,然后外部sapply(test, `[[`, "name") == "Submissions"
# [1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
# [19] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
遍历每个匹配项并提取sapply
。
我定义了id
,其中test <- input[[1]]
是您提供的数据(一个元素的列表)。
另一个选择是
input
在检查na.omit(sapply(test, function(x) if(x$name == "Submissions") x$id else NA))
的每个元素之后,如果存在匹配项,我们将立即返回test
。然后id
删除其余元素。