[R] New var

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Sat Jun 3 06:57:52 CEST 2017


You do understand that this is not the "do my work for me" mailing list, don't you? You should be asking questions like "why doesn't my code do one of these if conditions?" so that you know HOW to write the rest of them yourself. 

In addition you have been posting here long enough to know that your use of HTML format means we get a scrambled version of what you think you posted. Go do your homework this time (follow the Posting Guide) and come back with a question that helps us help you instead of asking for us to provide you with free work. 
-- 
Sent from my phone. Please excuse my brevity.

On June 2, 2017 8:49:11 PM PDT, Val <valkremk at gmail.com> wrote:
>Hi all,
>
>I have a data set with time interval and depending on the interval I
>want
>to create 5 more variables . Sample data below
>
>obs,   Start,   End
>1,2/1/2015,  1/1/2017
>2,4/11/2010, 1/1/2011
>3,1/4/2006,  5/3/2007
>4,10/1/2007, 1/1/2008
>5,6/1/2011,  1/1/2012
>6,10/15/2004,12/1/2004
>
>First, I want get  interval between the start date and end dates
>(End-start).
>
> obs,  Start , end, datediff
>1,2/1/2015,  1/1/2017, 700
>2,4/11/2010, 1/1/2011, 265
>3,1/4/2006,  5/3/2007, 484
>4,10/1/2007, 1/1/2008, 92
>5,6/1/2011,  1/1/2012, 214
>6,10/15/2004,12/1/2004,47
>
>Second. I want create 5 more variables  t1, t2, t3, t4 and  t5
>The value of each variable is defined as follows
>if datediff <   100 then  t1=1,  t2=t3=t4=t5=-1.
>if datediff >= 100 and  < 200 then  t1=0, t2=1,t3=t4=t5=-1,
>if datediff >= 200 and  < 300 then  t1=0, t2=0,t3=1,t4=t5=-1,
>if datediff >= 300 and  < 400 then  t1=0, t2=0,t3=0,t4=1,t5=-1,
>if datediff >= 400 and  < 500 then  t1=0, t2=0,t3=0,t4=0,t5=1,
>if datediff >= 500 then  t1=0, t2=0,t3=0,t4=0,t5=0
>
>The complete out put looks like as follow.
>obs, start,         end,    datediff,   t1, t2, t3, t4, t5
>1,    2/1/2015,   1/1/2017,    700, 0,  0,  0,  0,  0
>2,  4/11/2010,   1/1/2011,    265, 0,  0,  1, -1,  -1
>3,    1/4/2006,   5/3/2007,    484, 0,  0,  0, 0,   1
>4,   10/1/2007,  1/1/2008,      92, 1, -1, -1,-1,  -1
>5 ,    6/1/2011,    1/1/2012,  214,  0,  0,  1,-1,  -1
>6, 10/15/2004, 12/1/2004,     47, 1, -1, -1, -1, -1
>
>Thank you.
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list