I have a table which tells me if a client paid in cash or not and what she/he bought:
Client | Item | Cash
___________________________
John | CD | Yes
Billy | LP | Yes
Charles| DVD |
Mary | CD | Yes
Lucy | Book |
Sam | DVD |
Louis | CD | Yes
Mario | LP | Yes
And then, I want to create a dataframe only with the clients who paid in cash. Like this:
Client | Item | Cash
___________________________
John | CD | Yes
Billy | LP | Yes
Mary | CD | Yes
Louis | CD | Yes
Mario | LP | Yes
I tried this:
df %>%
group_by(cash)
You need to filter the rows where the payment is in Cash
library(dplyr)
df %>% filter(Cash=="Yes")
The group_by
function is useful if after you want to summarise the data by group (Cash or not): compute sums, counts, means...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.