2

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.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
John Karuitha
  • 331
  • 3
  • 11
  • Take a look at the language for expressing formatted text. https://stackoverflow.com/editing-help It will help you learn how to craft a question that is legible. – Chad Miller Apr 04 '20 at 16:45

1 Answers1

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)

stefan
  • 90,330
  • 6
  • 25
  • 51