r - Using purrr::map for recursive function call -


i have list within data frame on want use purrr::map() test whether there null elements , rid of them.

while able using sapply, map doesn't work. read https://cran.r-project.org/web/packages/purrr/purrr.pdf, can't figure out what's missing.

here's sapply code --this works well:

p_trans<- p_trans[!sapply(p_trans$group,is.null),]  

here's few things tried purrr::map, don't work.

here 4 things tried:

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)) 

can please correct mistake, , let me know doing wrong above 4 options?


data:

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")) 


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -