我遇到了一个奇怪的情况,当我在mutate
中使用dplyr::rowwise()
和min
时,它在所有行中输出一个值,而不是逐行输出。它在同一会话中与我的其他 Dataframe 一起工作,不确定是什么问题。我还重新启动了我的Rstudio。
df <- indf
dplyr::rowwise(.) %>%
mutate(test = min(as.Date(date1), as.Date(date2), na.rm = T)
structure(list(id = structure(c("5001", "3002", "2001", "1001",
"6001", "9001"), label = "Subject name or identifier", format.sas = "$"),
date1 = structure(c(NA, 18599, NA, NA, NA, NA), class = "Date"),
date2 = structure(c(18472, 18597, 18638, 18675, 18678, 18696
), class = "Date"), test = structure(c(18472, 18472, 18472,
18472, 18472, 18472), class = "Date")), class = c("rowwise_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -6L), groups = structure(list(
.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame")))
1条答案
按热度按时间o2g1uqev1#
这可能是由于在
dplyr
之后加载了plyr
包,从而从dplyr
中屏蔽了mutate
与使用
::
从dplyr加载函数的比较请注意,
rowwise
速度较慢,最好使用矢量化的pmin