These sample dataframes have data on the two segments of a piecewise regression line. In "df", segment_start is the beginning of the segment, and segment_end is the end of the segment. There is a data point for years 2000-2010. "value" is the slope of the segment. The first segment goes from 2000-2006 and the second from 2007-2010. What I'm trying to do is combine the rows for "obs" 1 into a single row, with all data points, 2000-2010, included, as shown in "df2". Is there a code to automate this process? Thank you for any ideas in advance.
#data I have:
df <- tibble("obs" = 1:1,
"segment"=c(1,2),
"segment_start"=c(2000,2006),
"segment_end"=c(2006, 2010),
"value"=c(0.5, 1.5))
df
#data I want:
df2 <- tibble("obs"=1,
"2000"=0.5,
"2001"=0.5,
"2002"=0.5,
"2003"=0.5,
"2004"=0.5,
"2005"=0.5,
"2006"=0.5,
"2007"=1.5,
"2008"=1.5,
"2009"=1.5,
"2010"=1.5)
df2