Re: [R] 2013-06-28 coverts to 15884?

2014-03-19 Thread Jim Lemon

On 03/20/2014 08:46 AM, Jason Rupert wrote:

MaxUpdated_row-NULL
MaxUpdated_val- 2013-06-28


rbind(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
   [,1]
[1,] 15884

c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))

[1] 15884

c(MaxUpdated_row, MaxUpdated_val)

[1] 15884


Evidently, I'm again missing something simple, as I would prefer to be able to 
see the actual date to be shown.

I found a work around, but I don't like it, as I have to convert back to date 
later:
c(MaxUpdated_row, as.character(MaxUpdated_val))


Hi Jason,
You aren't converting the date to something else, just displaying it as 
a character vector by using the format function. Whenever you form a 
vector, R tries to convert everything in it to the same data type. If 
you _assign_ that vector to something else:


mymax-c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))

you will have the date type in the MaxUpdated_val and the character type 
in mymax.


Jim

__
R-help@r-project.org 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] 2013-06-28 coverts to 15884?

2014-03-19 Thread Jason Rupert
Not sure I follow. 

I would like the date formatting information preserved as is implemented when 
using as.character: 
MaxUpdated_row-NULL
MaxUpdated_val- 2013-06-28

c(MaxUpdated_row, as.character(MaxUpdated_val))
[1] 2013-06-28

However, when I try to used as.Date(...) I loose the date formatting 
information:
c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
[1] 15884


I thought as.Date was an instruction describing how the data element should be 
represented?


Maybe as.character is the only way to preserve the date formatting 
information in character string format in a vector and then just convert it 
back later on...


Thanks again.




On Wednesday, March 19, 2014 5:42 PM, Jim Lemon j...@bitwrit.com.au wrote:
 
On 03/20/2014 08:46 AM, Jason Rupert wrote:

 MaxUpdated_row-NULL
 MaxUpdated_val- 2013-06-28


 rbind(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
        [,1]
 [1,] 15884

 c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
 [1] 15884
 c(MaxUpdated_row, MaxUpdated_val)
 [1] 15884

 Evidently, I'm again missing something simple, as I would prefer to be able 
 to see the actual date to be shown.

 I found a work around, but I don't like it, as I have to convert back to date 
 later:
 c(MaxUpdated_row, as.character(MaxUpdated_val))

Hi Jason,
You aren't converting the date to something else, just displaying it as 
a character vector by using the format function. Whenever you form a 
vector, R tries to convert everything in it to the same data type. If 
you _assign_ that vector to something else:

mymax-c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))

you will have the date type in the MaxUpdated_val and the character type 
in mymax.

Jim
[[alternative HTML version deleted]]

__
R-help@r-project.org 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] 2013-06-28 coverts to 15884?

2014-03-19 Thread William Dunlap
Instead of making your initial value of MaxUpdated_row  NULL,
make it a 0-long Date object.  Then c() will work as you wish
(but not rbind).  E.g.,

 MaxUpdated_row - as.Date(character(0))
 MaxUpdated_row - c(MaxUpdated_row, as.Date(2013-06-28, %Y-%m-%d))
 MaxUpdated_row - c(MaxUpdated_row, as.Date(2013-07-06, %Y-%m-%d))
 str(MaxUpdated_row)
 Date[1:2], format: 2013-06-28 2013-07-06

Bill Dunlap
TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Jason Rupert
 Sent: Wednesday, March 19, 2014 2:47 PM
 To: R-help@r-project.org
 Subject: [R] 2013-06-28 coverts to 15884?
 
 MaxUpdated_row-NULL
 MaxUpdated_val- 2013-06-28
 
 
 rbind(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
   [,1]
 [1,] 15884
 
 c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
 [1] 15884
 c(MaxUpdated_row, MaxUpdated_val)
 [1] 15884
 
 Evidently, I'm again missing something simple, as I would prefer to be able 
 to see the
 actual date to be shown.
 
 I found a work around, but I don't like it, as I have to convert back to date 
 later:
 c(MaxUpdated_row, as.character(MaxUpdated_val))
 
 Any alternatives suggestions are much appreciated.
   [[alternative HTML version deleted]]

__
R-help@r-project.org 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] 2013-06-28 coverts to 15884?

2014-03-19 Thread Pascal Oettli
Hello,

It works for me:

R MaxUpdated_row - NULL
R MaxUpdated_val - 2013-06-28
R
R
R rbind(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
  [,1]
[1,] 15884
R c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
[1] 15884
R c(MaxUpdated_row, MaxUpdated_val)
[1] 2013-06-28
R

Regards,
Pascal

On Thu, Mar 20, 2014 at 6:46 AM, Jason Rupert jasonkrup...@yahoo.com wrote:
 MaxUpdated_row-NULL
 MaxUpdated_val- 2013-06-28


 rbind(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
   [,1]
 [1,] 15884

 c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
[1] 15884
 c(MaxUpdated_row, MaxUpdated_val)
[1] 15884

 Evidently, I'm again missing something simple, as I would prefer to be able 
 to see the actual date to be shown.

 I found a work around, but I don't like it, as I have to convert back to date 
 later:
 c(MaxUpdated_row, as.character(MaxUpdated_val))

 Any alternatives suggestions are much appreciated.
 [[alternative HTML version deleted]]


 __
 R-help@r-project.org 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.




-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan

__
R-help@r-project.org 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] 2013-06-28 coverts to 15884?

2014-03-19 Thread Jim Lemon

On 03/20/2014 09:57 AM, Jason Rupert wrote:

Not sure I follow.

I would like the date formatting information preserved as is implemented
when using as.character:
MaxUpdated_row-NULL
MaxUpdated_val- 2013-06-28

c(MaxUpdated_row, as.character(MaxUpdated_val))
[1] 2013-06-28

However, when I try to used as.Date(...) I loose the date formatting
information:
c(MaxUpdated_row, as.Date(MaxUpdated_val, %Y-%m-%d))
[1] 15884

I thought as.Date was an instruction describing how the data element
should be represented?

Maybe as.character is the only way to preserve the date formatting
information in character string format in a vector and then just convert
it back later on...

As I wrote before, all of the data types in a vector object in R must be 
the same. So when you catenate (c) two things that are different data 
types, R coerces them to the same type. Because you are just displaying 
the values in the vector you have created, it doesn't change the data 
type of MaxUpdated_val:


MaxUpdated_val-as.Date(2013-06-28,%Y-%m-%d)
# prints as a formatted date
MaxUpdated_val
[1] 2013-06-28
# make a vector with a numeric and MaxUpdated_val
c(0,MaxUpdated_val)
# R coerces the value to numeric and prints both
[1] 0 15884
# now assign it to something
mynewmax-c(0,MaxUpdated_val)
# in mynewmax the value is numeric
mynewmax
[1] 0 15884
# but MaxUpdated_val is still a date type on its own
MaxUpdated_val
[1] 2013-06-28

Jim

__
R-help@r-project.org 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.