purrr中的map2()为什么不能连续工作?

问题描述 投票:0回答:1

我想根据“ check_in”和“ check_out”之前1天之间的日期顺序添加新列“ date_seq”。我使用purrrr:map2(check_in,check_out,〜seq(check_in,check_out-1,1))作为屏幕快照的附件。我尝试了2种方法,但是使用管道(第2行)的方法无法正常工作。可能是什么原因? enter image description here

r purrr
1个回答
0
投票

尝试使用:

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)
© www.soinside.com 2019 - 2024. All rights reserved.