【发布时间】:2020-12-17 00:30:43
【问题描述】:
目标:返回 thing1=F 和 thing2=MeFirst 的行
为什么这不起作用?
tibble(
row = 1:10,
thing1 = c(rep("F",5),rep("L",5)),
thing2 = c(rep("MeSecond",4),rep("MeFirst",2),rep("MeSecond",4))
) %>%
mutate(
thing1 = factor(thing1, levels = c("F", "L")),
thing2 = factor(thing2, levels = c("MeFirst", "MeSecond"))
) %>%
top_n(
.,
n = 1,
wt = rev(thing1)
) %>%
top_n(
.,
n = 1,
wt = rev(thing2)
)
以上返回行 2:5。
我知道这确实有效:
tibble(
row = 1:10,
thing1 = c(rep("F",5),rep("L",5)),
thing2 = c(rep("MeSecond",4),rep("MeFirst",2),rep("MeSecond",4))
) %>%
mutate(
thing1 = factor(thing1, levels = c("F", "L")),
thing2 = factor(thing2, levels = c("MeFirst", "MeSecond"))
) %>%
top_n(
.,
n = -1,
wt = thing1
) %>%
top_n(
.,
n = -1,
wt = thing2
)
但问题是,为什么 rev(thing2) 不起作用?
【问题讨论】: