I have a dataframe looks like below:
Year Person Office
2005 Peter Boston
2007 Peter Boston
2008 Peter Chicago
2009 Peter New York
2011 Peter New York
2003 Amy Seattle
2004 Amy Boston
2006 Amy Chicago
2007 Amy Chicago
I want to calculate a office-person level normalized measure (count) that captures the number of offices that a person experienced before coming to the current one. The measure is normalized by the total amount of years before arriving at the current position. Below is the ideal output. For Peter, Boston is his first office and thus, his normalized measure count for Boston is 0. For Peter, Chicago is his second office and he spent 2008-2005=3 years before coming to the Chicago office. Thus, his normalized measure count for Chicago is 1/3.
Office Person Count
Boston Peter 0
Boston Amy 1
Chicago Peter 1/3
Chicago Amy 2/3
New York Peter 1/2
Seattle Amy 0