I am trying to create a column vector by taking elements from two columns of a data frame one at a time (i.e. one element from var1 and then one element from var2, and then one element from var1 and so on) by using a loop.
Using the example data below, I tried to create a loop function with no success.
df1 <- data.frame(var1=c("female", "male", "female", "male"),
var2=c("group1", "group2", "group1", "group2"))
I expect the following output: "female" "group1" "male" "group2" "female" "group1" "male" "group2"