The pipe operator does not appear to work as advertised in the following operation outlined below:
library("dplyr")
library("tibble")
I could not automate by code within R, but downloading the 740 row, 32 column excel document indicated below then saving as "rus18.csv" in your working directory then saving it as "rus18.csv" in your working directory will allow this code to work
path = "https://www.opm.gov/policy-data-oversight/pay-leave/salaries-wages/2018/2018-general-schedule-pay-rates.xls"
Read file as tibble:
rus18 <- as_tibble(read.csv("rus18.csv"))
verify that dplyr operation works alone. The following two lines do the same thing:
filter(rus18, LOCNAME == "RUS")
rus18 %>% filter(LOCNAME == "RUS")
Same with these two:
select(rus18, starts_with("HOURLY"))
rus18 %>% select(starts_with("HOURLY"))
But putting them together gives "Error in filter_impl(.data, dots) : object 'LOCNAME' not found"
rus17 %>% select(starts_with("HOURLY")) %>% filter(LOCNAME == "RUS")
You no longer have the column LOCNAME
when you chain the two like that. The select
call has kept only columns with names starting with "HOURLY"
, so of course there is no more column to check for the value "RUS"
.
Try this way around:
rus17 %>% filter(LOCNAME == "RUS") %>% select(starts_with("HOURLY"))