[R] Date variable
Dear R users, I did following with a date variable library(date) date = 03/11/05 date = as.Date(date, format=%m/%d/%y) date [1] 2005-03-11 s = vector(length=3) s[1] = date s[1] [1] 12853 But here I got s[1] as 12853. But this is not that I want. I need s[1] as original date. Can anyone tell me where is the mistake? Thanks and regards, - Heres a new way to find what you're looking for - Yahoo! Answers [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list 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.
Re: [R] Date variable
For Date class, *original* (that is, contents in memory) is 12853, and 2005-03-11 is one expression of the original. So you have to convert from the original to the charecter expression as follows. s[1]-format(date) s [1] 2005-03-11 FALSE FALSE s[1]-as.character(date) s [1] 2005-03-11 FALSE FALSE BTW, I think s = vector(character, length=3) is more preferable for your purpose. HTH. On 1/24/07, stat stat [EMAIL PROTECTED] wrote: Dear R users, I did following with a date variable library(date) date = 03/11/05 date = as.Date(date, format=%m/%d/%y) date [1] 2005-03-11 s = vector(length=3) s[1] = date s[1] [1] 12853 But here I got s[1] as 12853. But this is not that I want. I need s[1] as original date. Can anyone tell me where is the mistake? Thanks and regards, - Here's a new way to find what you're looking for - Yahoo! Answers [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list 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.
Re: [R] Date variable
You don't appear to be using any functionality from the date package but are using the Date class which is built into the base of R. Assuming: d - as.Date(03/11/05, %m/%d/%y) # and try one of these: d3 - structure(rep(NA, 3), class = Date) d3[1] - d d3 # or d3 - rep(d, 3) + NA d3[1] - d d3 # or d3 - rep(NA, 3) class(d3) - Date d3[1] - d d3 # or d3 - vector(length = 3, mode = numeric) + NA class(d3) - Date d3[1] - d d3 On 1/24/07, stat stat [EMAIL PROTECTED] wrote: Dear R users, I did following with a date variable library(date) date = 03/11/05 date = as.Date(date, format=%m/%d/%y) date [1] 2005-03-11 s = vector(length=3) s[1] = date s[1] [1] 12853 But here I got s[1] as 12853. But this is not that I want. I need s[1] as original date. Can anyone tell me where is the mistake? Thanks and regards, - Here's a new way to find what you're looking for - Yahoo! Answers [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list 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. __ R-help@stat.math.ethz.ch mailing list 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.