问题
I am using R and exercising using the dslabs data for murders in the USA. As follows,
library(dslabs)
data("murders")
library(tidyverse)
murders <- mutate(murders, pop_in_millions = population / 10^6)
murders <- mutate(murders, rate = total/population * 100000)
murders <- mutate(murders, rank(-rate))
select(murders, state, rank)
Error: This tidyselect interface doesn't support predicates yet.
i Contact the package author and suggest using eval_select()
.
Run rlang::last_error()
to see where the error occurred.
回答1:
In your last mutate call you forgot to create the rank
variable. Therefore select
can't find a column named rank
in your dataset. The somewhat mysterious error message is related to the fact that R
instead thinks you want to do something with the rank
function. Try this:
library(dslabs)
data("murders")
library(tidyverse)
murders <- mutate(murders, pop_in_millions = population / 10^6)
murders <- mutate(murders, rate = total/population * 100000)
murders <- mutate(murders, rank = rank(-rate))
head(select(murders, state, rank))
#> state rank
#> 1 Alabama 23
#> 2 Alaska 27
#> 3 Arizona 10
#> 4 Arkansas 17
#> 5 California 14
#> 6 Colorado 38
Created on 2020-04-04 by the reprex package (v0.3.0)
来源:https://stackoverflow.com/questions/61022423/tidyverse-this-tidyselect-interface-doesnt-support-predicates-yet