2  Keeping rows

keep takes a condition and keeps the rows where it holds.

sales |> keep(region == "West")
region product revenue cost
West Widget 100 40
West Widget 200 50
West Gadget 300 100
West Gadget 150 50
sales >> keep(col.region == "West")
region product revenue cost
West Widget 100 40
West Widget 200 50
West Gadget 300 100
West Gadget 150 50

Conditions combine with and and or, and either language’s negation reverses one.

sales |> keep(revenue > 150 & cost < 100)
region product revenue cost
West Widget 200 50
sales >> keep((col.revenue > 150) & (col.cost < 100))
region product revenue cost
West Widget 200 50

There is no separate verb for dropping rows. Removing the rows where something is true is keeping the rows where it is false, and one verb says both.

sales |> keep(!(product == "Widget"))
region product revenue cost
West Gadget 300 100
West Gadget 150 50
sales >> keep(~(col.product == "Widget"))
region product revenue cost
West Gadget 300 100
West Gadget 150 50