rpietro / ecd_jama_renewal

0 stars 0 forks source link

change dates into years #3

Open mworni opened 11 years ago

mworni commented 11 years ago

I try to create a variable for year of transplant. I found a variable named TX_DATE which contains values as

6/23/1999 6/25/2008 6/26/1990 6/27/2003 3 3 3 3 3 3 3 6/28/2000 6/29/2006 6/7/1992 7/1/2003 7/1/2010 7/11/2000 7/15/2010 3 3 3 3 3 3 3 7/16/2007 7/21/2009 7/24/2003 7/26/2010...

How can I transform them into year variables?

In the script, I started with some thoughts on this on line 124

rpietro commented 11 years ago

here is what i would recommend:

  1. find out what the current class for the variable is ?class
  2. if it is not date (likely), convert it to date ?as.date http://goo.gl/adp3V
  3. there are multiple ways to extract the year
    1. year_variable <- as.numeric(format(variable, "%Y"))
    2. year_variable <- as.POSIXlt(variable)$year + 1900

On Tue, Dec 4, 2012 at 4:20 PM, mworni notifications@github.com wrote:

I try to create a variable for year of transplant. I found a variable named TX_DATE which contains values as

6/23/1999 6/25/2008 6/26/1990 6/27/2003 3 3 3 3 3 3 3 6/28/2000 6/29/2006 6/7/1992 7/1/2003 7/1/2010 7/11/2000 7/15/2010 3 3 3 3 3 3 3 7/16/2007 7/21/2009 7/24/2003 7/26/2010...

How can I transform them into year variables?

In the script, I started with some thoughts on this on line 124

— Reply to this email directly or view it on GitHubhttps://github.com/rpietro/ecd_jama_renewal/issues/3.

mworni commented 11 years ago

i actuallytried to convert from as i remember faxtorto date but this did not work. will try again tomorrow. On Dec 4, 2012 10:39 PM, "Ricardo Pietrobon" notifications@github.com wrote:

here is what i would recommend:

  1. find out what the current class for the variable is ?class
  2. if it is not date (likely), convert it to date ?as.date http://goo.gl/adp3V
  3. there are multiple ways to extract the year
  4. year_variable <- as.numeric(format(variable, "%Y"))
  5. year_variable <- as.POSIXlt(variable)$year + 1900

On Tue, Dec 4, 2012 at 4:20 PM, mworni notifications@github.com wrote:

I try to create a variable for year of transplant. I found a variable named TX_DATE which contains values as

6/23/1999 6/25/2008 6/26/1990 6/27/2003 3 3 3 3 3 3 3 6/28/2000 6/29/2006 6/7/1992 7/1/2003 7/1/2010 7/11/2000 7/15/2010 3 3 3 3 3 3 3 7/16/2007 7/21/2009 7/24/2003 7/26/2010...

How can I transform them into year variables?

In the script, I started with some thoughts on this on line 124

— Reply to this email directly or view it on GitHub< https://github.com/rpietro/ecd_jama_renewal/issues/3>.

— Reply to this email directly or view it on GitHubhttps://github.com/rpietro/ecd_jama_renewal/issues/3#issuecomment-11016862.

rpietro commented 11 years ago

i would check the examples, you have to match the current format with the format in the syntax. see the doc i sent you. if it doesn't work, just send the command you used and the error message

On Tue, Dec 4, 2012 at 4:52 PM, mworni notifications@github.com wrote:

i actuallytried to convert from as i remember faxtorto date but this did not work. will try again tomorrow. On Dec 4, 2012 10:39 PM, "Ricardo Pietrobon" notifications@github.com wrote:

here is what i would recommend:

  1. find out what the current class for the variable is ?class
  2. if it is not date (likely), convert it to date ?as.date http://goo.gl/adp3V
  3. there are multiple ways to extract the year
  4. year_variable <- as.numeric(format(variable, "%Y"))
  5. year_variable <- as.POSIXlt(variable)$year + 1900

On Tue, Dec 4, 2012 at 4:20 PM, mworni notifications@github.com wrote:

I try to create a variable for year of transplant. I found a variable named TX_DATE which contains values as

6/23/1999 6/25/2008 6/26/1990 6/27/2003 3 3 3 3 3 3 3 6/28/2000 6/29/2006 6/7/1992 7/1/2003 7/1/2010 7/11/2000 7/15/2010 3 3 3 3 3 3 3 7/16/2007 7/21/2009 7/24/2003 7/26/2010...

How can I transform them into year variables?

In the script, I started with some thoughts on this on line 124

— Reply to this email directly or view it on GitHub< https://github.com/rpietro/ecd_jama_renewal/issues/3>.

— Reply to this email directly or view it on GitHub< https://github.com/rpietro/ecd_jama_renewal/issues/3#issuecomment-11016862>.

— Reply to this email directly or view it on GitHubhttps://github.com/rpietro/ecd_jama_renewal/issues/3#issuecomment-11017385.