0
 chase_2021 = chase[c(143:1020),]
 
 paychecks = chase_2021 %>% 
     select(Posting.Date, Amount, Description, starts_with('CVS'), ends_with('PPD ID: 9953382345')) %>% 
     filter(Amount > 100, Amount < 1000)

I'm currently trying to find my paychecks from last year based on a dataset I downloaded from one of my bank accounts. If I subet for transactions that were more than $100, R displays money I earned through my employer, but also through investments and cash I received from people who owed me at the time. Paychecks from my employer are listed on CVS PAYROLL PPID under the Description column. The code above still displays the earnings I received from my employer and others. Also, I couldn't subset the columns by year with ends_with(2021) So I had to filter with column numbers.

alan503
  • 3
  • 2
  • 1
    Please read about [how to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and update your question accordingly. Include a sample of your data by pasting the output of `dput()` into your post or `dput(head())` if you have a large data frame. Also include code you have tried and any relevant errors. If you cannot post your data, then please post code for creating representative data. – LMc May 13 '22 at 20:08
  • 1
    The `select` statement is for selecting variables from your data. It seems you want to pick rows with specific conditions, which is what `filter` is for. You probably want something like `filter(Amount > 100, Amount < 1000, grep("^CSV", Description), lubridate::year(Posting.Date) == 2021)`. This depends on `Posting.Date` being a date object. It's unclear what variable might contain the substring `'PPD ID: 9953382345'`. – LMc May 13 '22 at 20:11
  • 1
    Anything in the `select()` statement is for choosing columns, not rows. If you want to filter values in columns, you need to do that in the `filter()` command. You cannot use `starts_with` or `ends_with` with values in the data.frame but you can use the base `startWith()` and `endsWith()` function for string matching. – MrFlick May 13 '22 at 20:12

0 Answers0