I have been able to use which()
to extract data from two individual columns based on a given criteria:
# cars with 6 cylinders
cyl_6 <- which(mtcars$cyl == 6)
# cars with 4 gears
gear_4 <- which(mtcars$gear == 4)
Respectively these return:
> cyl_6
[1] 1 2 4 6 10 11 30
> gear_4
[1] 1 2 3 8 9 10 11 18 19 20 26 32
How can I compare these two objects to get the common values into a new object? I'm expecting the outcome to be:
> cyl_6_gear_4
[1] 1 2 10 11