Challenge: I have a column in which there are several rows. For eg., the first row is "Fruit name" and second row is "Fruit Color" and it repeats for another fruit. I want to grab the every second row (Fruit color) and create a new column. In the original column only the fruit names remain.
I would like to go from df_before to df_after.
I'm sure there is a easier way to do this using functions from tidyverse (dplyr?) but couldn't find any info with a good deal of search. Would appreciate any pointers. Thanks in advance!
Fruit Color
1 Apple Red
2 Banana Yellow
3 Kiwi Grey
4 Grapes Green
The logic is simple:
step-1: copy the original column as the second column
step-2: shift the second column up by one with the function "lead"
step-3: delete the odd-rows using dplyr command
step-4: rename the first two columns