We have the mtcars
dataset and want to compute a function between different cars in groups taking several columns as input.
More specifically:
- Group by transmission
am
and gearsgear
- Compare all cars within the same group with each other (car1 to car2, car1 to car3, car2 to car3...)
- Does the first car have more displacement than the second car?
disp1>disp2
- AND does the first car have more horsepower than the second car?
hp1>hp2
The result should look like this:
# Car1 Car2 result
# Mazda RX4 Mazda RX4 Wag false
# Mazda RX4 Datsun 710 false
# Mazda RX4 Wag Datsun 710 true
In this question is an outer operation by group, but only a single column is used. Is it possible to expand this to several columns? If possible, it would be nice to have the disp1
, disp2
etc. columns in the result table.