I am stuck in transforming an existing data frame in R, using dplyr (but open for other options. I am running out of ideas and nothing brings me closer to the required result. The data frame looks like that:
data.frame("group" = c('a', 'a', 'b', 'b', 'c', 'c' ), "condition"= c(1, 2, 1, 2, 1,2 ), "X1" = c(2010,'x', 2011, 'x', 2010, 'x'), "X2" = c(2011,'x', 2012, 'x', 2011, 'x'), "X3" = c(2012,'x', 2013, 'x', 2012, 'x'), "X4" = c(2013,'x', 2014, 'x', 2013, 'x'), "X5" = c(2014,'', 2015, 'x', 2014, 'x'), "X6" = c(2015,'', 2015, '', 2015, ''))
For each group, the new data frame should show the earliest and last year (condition 1) that contains an 'x' in condition 2.
The result should look like:
data.frame("group" = c('a', 'b', 'c' ), "min"= c(2010, 2011, 2010), "max" = c(2013, 2015, 2014))