【问题标题】:Why map2() in purrr doesn't work consistently?为什么 purrr 中的 map2() 不能始终如一地工作?
【发布时间】:2020-05-10 13:08:25
【问题描述】:

我想根据“check_in”和“check_out”前 1 天之间的日期顺序添加新列“date_seq”。我使用 purrrr:map2(check_in, check_out, ~ seq(check_in, check_out - 1, 1)) 作为屏幕截图。我尝试了 2 种方法,但使用管道(第 2 行)的方法没有按预期工作。可能是什么原因?

【问题讨论】:

    标签: r purrr


    【解决方案1】:

    尝试使用:

    library(dplyr)
    
    test_df %>%
      mutate(date = purrr::map2(check_in, check_out, ~ seq(.x, .y - 1, 'day'))) %>%
      tidyr::unnest(date) %>%
      select(-check_in, check_out)
    

    【讨论】:

    • ...哦,我想念“变异”动词。我的愚蠢错误。无论如何,您只需一次帮助解决 2 个问题。非常感谢您的快速响应。
    猜你喜欢
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多