要素purrr::map()
があるかどうかをテストしてから削除するために使用したいデータフレーム内のリストがあります。NULL
sapply を使用してこれを行うことはできましたが、マップは機能しません。https://cran.r-project.org/web/packages/purrr/purrr.pdfを読みましたが、何が欠けているのかわかりません。
これが私のsapplyコードです - これはうまくいきます:
P_Trans<- P_Trans[!sapply(P_Trans$Group,is.null),]
のために試したことがいくつかありpurrr::map
ますが、うまくいきません。
試したことは以下の4つです。
a)
P_Trans %>% purrr::map(.,~is.null(Group))
b)
P_Trans %>% purrr::map(.,~is.null(.$Group))
c)
P_Trans %>% purrr::map(~is.null(.$Group))
d)
P_Trans %>% purrr::map(~is.null(Group))
誰かが私の間違いを訂正して、上記の 4 つのオプションで間違っていることを教えてもらえますか?
データ:
dput(P_Trans)
structure(list(TransactionID = c("a1", "a1", "a1", "a2", "a2",
"a2", "a3", "a3", "a3", "a3", "a4", "a5", "a5", "a5", "a5", "a5",
"a6", "a6", "a7"), ProductID = c("A", "B", "1", "C", "4", "5",
"D", "C", "7", "8", "H", "1", "2", "3", "3", "1", "H", "15",
"22"), ProductType = c(1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 2,
2, 2, 2, 1, 2, 3), Group = list(structure(list(Group = "Group1"), .Names = "Group", row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group1"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group1"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = c("Group2", "Group3")), .Names = "Group", row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group2"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group2"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group3"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = c("Group2", "Group3")), .Names = "Group", row.names = c(NA,
-2L), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group3"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group3"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group5"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group1"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group1"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group1"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group1"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group1"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group5"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), structure(list(
Group = "Group5"), .Names = "Group", row.names = c(NA, -1L
), class = c("tbl_df", "tbl", "data.frame")), NULL)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -19L), .Names = c("TransactionID",
"ProductID", "ProductType", "Group"))