Re: [R] as.Date and ylim in empty plot: RESOLVED

2018-09-22 Thread David Winsemius


> On Sep 19, 2018, at 10:48 PM, Ogbos Okike  wrote:
> 
> Hi David,
> That's it!!! The outcome is attached.

The explanation for this is that columns that have digits separated by dashes 
will not be interpreted by R's read.table() as numeric or dates, but rather as 
the default for text entries:  as R factors. Factors are stored as numbers with 
an associated attribute that gets used to display the meaning of those numbers. 
Since the numbers used are integers from 1 to the count of unique items, using 
the xlim = as.numeric(as.Date(.)) creates values are far outside the range of 
the factor integers and nothing gets displayed as a result. If you had used 
range(as.numeric()) you might have seen something. 
Whether it was what you wanted to see  well, that's another matter!

Good luck understanding R factors. Some research centers have adopted a policy 
of setting the option used by read.table for that behavior with:

options(stringsAsFactors= FALSE)  # can be set in .Rprofile or other "startup" 
file.

That produces text rather than factors by default and might result in less 
confusion.

-- 
David.
> 
> Many thanks please.
> 
> Best
> Ogbos
> 
> On Wed, Sep 19, 2018 at 11:34 PM David Winsemius  
> wrote:
> 
> > On Sep 19, 2018, at 7:55 AM, Ogbos Okike  wrote:
> > 
> > Dear Experts,
> > I generated the plot attached. Every other thing is OK except the black
> > horizontal lines which should appear like points or dots as the coloured
> > ones. I can't understand why.
> > 
> > I tried to change it to look like dots by calling empty plots so that I
> > will add them as points.
> > 
> > Since I have a range of date that can fall any where within 2005, I tried:
> > 
> > plot(1, type="n", xlab="", ylab="",
> > xlim=c(as.Date("2005-01-01"),as.Date("2005-12-31")), ylim=c(-.5, -10))
> > 
> > ylim worked fine but xlim instead of appearing like date as indicated on
> > the x-axes of the attached plot, translated to ordinary numbers (12800,
> > 12900,13000, 13100).
> > 
> > All the data is of the same format:
> > 2005-01-04 -2.76105935648091
> > 2005-01-19 -9.60813496025994
> > 2005-01-22 -7.92101965866777
> > 2005-02-19 -1.61308152604905
> > 2005-02-24 -1.51497015807712
> > 2005-05-09 -2.06465797304654
> > 2005-05-11 -1.14840389007051
> > 2005-05-16 -3.85281900888504
> > 2005-06-13 -1.18659683796617
> > 2005-06-17 -3.48787712566258
> > 2005-06-22 -1.14223758296308
> > 2005-07-18 -4.96013018907366
> > 2005-08-03 -1.24313324914368
> > 2005-08-07 -2.96672894841722
> > 2005-08-10 -1.11868063781156
> > 2005-08-25 -1.46453734930983
> > 2005-09-13 -8.00895215754776
> > 2005-09-15 -6.63439065989452
> > 2005-10-13 -2.25054996925846
> > 2005-12-15 -1.08933890547705
> 
> You did not succeed in creating a plot that the rhelp mail server would 
> accept. My guess is that the first column is a factor variable and that you 
> did not use colClasses when doing your data input.
> 
> dd <- read.table(text="2005-01-04 -2.76105935648091
> 2005-01-19 -9.60813496025994
> 2005-01-22 -7.92101965866777
> 2005-02-19 -1.61308152604905
> 2005-02-24 -1.51497015807712
> 2005-05-09 -2.06465797304654
> 2005-05-11 -1.14840389007051
> 2005-05-16 -3.85281900888504
> 2005-06-13 -1.18659683796617
> 2005-06-17 -3.48787712566258
> 2005-06-22 -1.14223758296308
> 2005-07-18 -4.96013018907366
> 2005-08-03 -1.24313324914368
> 2005-08-07 -2.96672894841722
> 2005-08-10 -1.11868063781156
> 2005-08-25 -1.46453734930983
> 2005-09-13 -8.00895215754776
> 2005-09-15 -6.63439065989452
> 2005-10-13 -2.25054996925846
> 2005-12-15 -1.08933890547705", colClasses=c("Date","numeric")
> )
> 
> 
> No problems with:
> 
>  plot(dd[[1]], dd[[2]], xlim=c(as.Date("2005-01-01"),as.Date("2005-12-31")))
> 
> 
> (Not a particularly good test of the use of an xlim argument since nothing 
> was excluded.)
> 
> PDF's are accepted. PNGs are not.
> 
> -- 
> David.
> > 
> > Thank you so much for your input.
> > 
> > Best regards
> > Ogbos
> > __
> > R-help@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.
> 
> David Winsemius
> Alameda, CA, USA
> 
> 'Any technology distinguishable from magic is insufficiently advanced.'   
> -Gehm's Corollary to Clarke's Third Law
> 
> 
> 
> 
> 
> 

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

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


Re: [R] as.Date and ylim in empty plot: RESOLVED

2018-09-19 Thread Ogbos Okike
Hi David,
That's it!!! The outcome is attached.

Many thanks please.

Best
Ogbos

On Wed, Sep 19, 2018 at 11:34 PM David Winsemius 
wrote:

>
> > On Sep 19, 2018, at 7:55 AM, Ogbos Okike 
> wrote:
> >
> > Dear Experts,
> > I generated the plot attached. Every other thing is OK except the black
> > horizontal lines which should appear like points or dots as the coloured
> > ones. I can't understand why.
> >
> > I tried to change it to look like dots by calling empty plots so that I
> > will add them as points.
> >
> > Since I have a range of date that can fall any where within 2005, I
> tried:
> >
> > plot(1, type="n", xlab="", ylab="",
> > xlim=c(as.Date("2005-01-01"),as.Date("2005-12-31")), ylim=c(-.5, -10))
> >
> > ylim worked fine but xlim instead of appearing like date as indicated on
> > the x-axes of the attached plot, translated to ordinary numbers (12800,
> > 12900,13000, 13100).
> >
> > All the data is of the same format:
> > 2005-01-04 -2.76105935648091
> > 2005-01-19 -9.60813496025994
> > 2005-01-22 -7.92101965866777
> > 2005-02-19 -1.61308152604905
> > 2005-02-24 -1.51497015807712
> > 2005-05-09 -2.06465797304654
> > 2005-05-11 -1.14840389007051
> > 2005-05-16 -3.85281900888504
> > 2005-06-13 -1.18659683796617
> > 2005-06-17 -3.48787712566258
> > 2005-06-22 -1.14223758296308
> > 2005-07-18 -4.96013018907366
> > 2005-08-03 -1.24313324914368
> > 2005-08-07 -2.96672894841722
> > 2005-08-10 -1.11868063781156
> > 2005-08-25 -1.46453734930983
> > 2005-09-13 -8.00895215754776
> > 2005-09-15 -6.63439065989452
> > 2005-10-13 -2.25054996925846
> > 2005-12-15 -1.08933890547705
>
> You did not succeed in creating a plot that the rhelp mail server would
> accept. My guess is that the first column is a factor variable and that you
> did not use colClasses when doing your data input.
>
> dd <- read.table(text="2005-01-04 -2.76105935648091
> 2005-01-19 -9.60813496025994
> 2005-01-22 -7.92101965866777
> 2005-02-19 -1.61308152604905
> 2005-02-24 -1.51497015807712
> 2005-05-09 -2.06465797304654
> 2005-05-11 -1.14840389007051
> 2005-05-16 -3.85281900888504
> 2005-06-13 -1.18659683796617
> 2005-06-17 -3.48787712566258
> 2005-06-22 -1.14223758296308
> 2005-07-18 -4.96013018907366
> 2005-08-03 -1.24313324914368
> 2005-08-07 -2.96672894841722
> 2005-08-10 -1.11868063781156
> 2005-08-25 -1.46453734930983
> 2005-09-13 -8.00895215754776
> 2005-09-15 -6.63439065989452
> 2005-10-13 -2.25054996925846
> 2005-12-15 -1.08933890547705", colClasses=c("Date","numeric")
> )
>
>
> No problems with:
>
>  plot(dd[[1]], dd[[2]],
> xlim=c(as.Date("2005-01-01"),as.Date("2005-12-31")))
>
>
> (Not a particularly good test of the use of an xlim argument since nothing
> was excluded.)
>
> PDF's are accepted. PNGs are not.
>
> --
> David.
> >
> > Thank you so much for your input.
> >
> > Best regards
> > Ogbos
> > __
> > R-help@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.
>
> David Winsemius
> Alameda, CA, USA
>
> 'Any technology distinguishable from magic is insufficiently advanced.'
>  -Gehm's Corollary to Clarke's Third Law
>
>
>
>
>
>


Ogbos.pdf
Description: Adobe PDF document
__
R-help@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.


Re: [R] as.Date and ylim in empty plot

2018-09-19 Thread David Winsemius

> On Sep 19, 2018, at 7:55 AM, Ogbos Okike  wrote:
> 
> Dear Experts,
> I generated the plot attached. Every other thing is OK except the black
> horizontal lines which should appear like points or dots as the coloured
> ones. I can't understand why.
> 
> I tried to change it to look like dots by calling empty plots so that I
> will add them as points.
> 
> Since I have a range of date that can fall any where within 2005, I tried:
> 
> plot(1, type="n", xlab="", ylab="",
> xlim=c(as.Date("2005-01-01"),as.Date("2005-12-31")), ylim=c(-.5, -10))
> 
> ylim worked fine but xlim instead of appearing like date as indicated on
> the x-axes of the attached plot, translated to ordinary numbers (12800,
> 12900,13000, 13100).
> 
> All the data is of the same format:
> 2005-01-04 -2.76105935648091
> 2005-01-19 -9.60813496025994
> 2005-01-22 -7.92101965866777
> 2005-02-19 -1.61308152604905
> 2005-02-24 -1.51497015807712
> 2005-05-09 -2.06465797304654
> 2005-05-11 -1.14840389007051
> 2005-05-16 -3.85281900888504
> 2005-06-13 -1.18659683796617
> 2005-06-17 -3.48787712566258
> 2005-06-22 -1.14223758296308
> 2005-07-18 -4.96013018907366
> 2005-08-03 -1.24313324914368
> 2005-08-07 -2.96672894841722
> 2005-08-10 -1.11868063781156
> 2005-08-25 -1.46453734930983
> 2005-09-13 -8.00895215754776
> 2005-09-15 -6.63439065989452
> 2005-10-13 -2.25054996925846
> 2005-12-15 -1.08933890547705

You did not succeed in creating a plot that the rhelp mail server would accept. 
My guess is that the first column is a factor variable and that you did not use 
colClasses when doing your data input.

dd <- read.table(text="2005-01-04 -2.76105935648091
2005-01-19 -9.60813496025994
2005-01-22 -7.92101965866777
2005-02-19 -1.61308152604905
2005-02-24 -1.51497015807712
2005-05-09 -2.06465797304654
2005-05-11 -1.14840389007051
2005-05-16 -3.85281900888504
2005-06-13 -1.18659683796617
2005-06-17 -3.48787712566258
2005-06-22 -1.14223758296308
2005-07-18 -4.96013018907366
2005-08-03 -1.24313324914368
2005-08-07 -2.96672894841722
2005-08-10 -1.11868063781156
2005-08-25 -1.46453734930983
2005-09-13 -8.00895215754776
2005-09-15 -6.63439065989452
2005-10-13 -2.25054996925846
2005-12-15 -1.08933890547705", colClasses=c("Date","numeric")
)


No problems with:

 plot(dd[[1]], dd[[2]], xlim=c(as.Date("2005-01-01"),as.Date("2005-12-31")))


Rplots.pdf
Description: Adobe PDF document


(Not a particularly good test of the use of an xlim argument since nothing was 
excluded.)

PDF's are accepted. PNGs are not.

-- 
David.
> 
> Thank you so much for your input.
> 
> Best regards
> Ogbos
> __
> R-help@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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law





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


Re: [R] as.Date and ylim in empty plot

2018-09-19 Thread MacQueen, Don via R-help
I'm a little surprised at some of what happens, but you can get date labels on 
the x axis like this:

drng <- as.Date( c('2005-1-1' , '2005-12-31') )
plot(1, type="n", xlab="", ylab="", xaxt='n', xlim=drng, ylim=c(-.5, -10))
axis(1, at= pretty(drng), lab=format(pretty(drng)))

and if you prefer some other date format, specify it in the call to format()

Did you intend to reverse the direction of your  y axis?

-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 9/19/18, 7:55 AM, "R-help on behalf of Ogbos Okike" 
 wrote:

Dear Experts,
I generated the plot attached. Every other thing is OK except the black
horizontal lines which should appear like points or dots as the coloured
ones. I can't understand why.

I tried to change it to look like dots by calling empty plots so that I
will add them as points.

Since I have a range of date that can fall any where within 2005, I tried:

plot(1, type="n", xlab="", ylab="",
xlim=c(as.Date("2005-01-01"),as.Date("2005-12-31")), ylim=c(-.5, -10))

ylim worked fine but xlim instead of appearing like date as indicated on
the x-axes of the attached plot, translated to ordinary numbers (12800,
12900,13000, 13100).

All the data is of the same format:
2005-01-04 -2.76105935648091
2005-01-19 -9.60813496025994
2005-01-22 -7.92101965866777
2005-02-19 -1.61308152604905
2005-02-24 -1.51497015807712
2005-05-09 -2.06465797304654
2005-05-11 -1.14840389007051
2005-05-16 -3.85281900888504
2005-06-13 -1.18659683796617
2005-06-17 -3.48787712566258
2005-06-22 -1.14223758296308
2005-07-18 -4.96013018907366
2005-08-03 -1.24313324914368
2005-08-07 -2.96672894841722
2005-08-10 -1.11868063781156
2005-08-25 -1.46453734930983
2005-09-13 -8.00895215754776
2005-09-15 -6.63439065989452
2005-10-13 -2.25054996925846
2005-12-15 -1.08933890547705

Thank you so much for your input.

Best regards
Ogbos
__
R-help@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.


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


Re: [R] as.Date() function

2018-08-21 Thread John Kane via R-help
You loaded "lubridate" so using Erin's approach 

library(lubridate)
st <- c("1961-01","1961-04","1983-02")
dat1 <- ymd(paste( st, "01",  sep ="-"))
 

On Monday, August 20, 2018, 1:15:56 a.m. EDT, 
 wrote:  
 
 Thanks Erin and Jim. You have indeed solved my problem.

Philip


Quoting Erin Hodgess :

> Hi Philip:
>
> Here is something to consider:
>
>> #potential solution:
>> sta <- paste(st,"-01",sep="")
>> st1 <- as.Date(sta, format=("%Y-%m-%d"))
>> print(st1)
> [1] "1961-01-01" "1961-04-01" "1983-02-01"
>
>
> Hope this helps!
> Erin
>
> Erin Hodgess, PhD
> mailto: erinm.hodg...@gmail.com
>
>
> On Sun, Aug 19, 2018 at 3:25 PM  wrote:
>
>> I am having trouble with what must be a very simple problem. Here is a
>> reproducible example:
>>
>> library(lubridate)
>> st <- c("1961-01","1961-04","1983-02")
>> print(st)
>> #[1] "1961-01" "1961-04" "1983-02"
>> st1 <- as.Date(st, format=("%Y-%m"))
>> print(st1)
>> #[1] NA NA NA
>>
>> Why the heck am I getting three NAs instead of three Dates?I have
>> studied the R documentation for as.Date() and it has not turned on the
>> light bulb for me.
>>
>> __
>> R-help@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.
>>

__
R-help@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.
  
[[alternative HTML version deleted]]

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


Re: [R] as.Date() function

2018-08-21 Thread Erin Hodgess
Nice one!


On Tue, Aug 21, 2018 at 6:14 PM John Kane  wrote:

> You loaded "lubridate" so using Erin's approach
>
> library(lubridate)
> st <- c("1961-01","1961-04","1983-02")
> dat1 <- ymd(paste( st, "01",  sep ="-"))
>
>
> On Monday, August 20, 2018, 1:15:56 a.m. EDT, <
> phili...@cpanel1.stormweb.net> wrote:
>
>
> Thanks Erin and Jim. You have indeed solved my problem.
>
> Philip
>
>
> Quoting Erin Hodgess :
>
> > Hi Philip:
> >
> > Here is something to consider:
> >
> >> #potential solution:
> >> sta <- paste(st,"-01",sep="")
> >> st1 <- as.Date(sta, format=("%Y-%m-%d"))
> >> print(st1)
> > [1] "1961-01-01" "1961-04-01" "1983-02-01"
> >
> >
> > Hope this helps!
> > Erin
> >
> > Erin Hodgess, PhD
> > mailto: erinm.hodg...@gmail.com
> >
> >
> > On Sun, Aug 19, 2018 at 3:25 PM  wrote:
> >
> >> I am having trouble with what must be a very simple problem. Here is a
> >> reproducible example:
> >>
> >> library(lubridate)
> >> st <- c("1961-01","1961-04","1983-02")
> >> print(st)
> >> #[1] "1961-01" "1961-04" "1983-02"
> >> st1 <- as.Date(st, format=("%Y-%m"))
> >> print(st1)
> >> #[1] NA NA NA
> >>
> >> Why the heck am I getting three NAs instead of three Dates?I have
> >> studied the R documentation for as.Date() and it has not turned on the
> >> light bulb for me.
> >>
> >> __
> >> R-help@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.
> >>
>
> __
> R-help@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.
>
-- 
Erin Hodgess, PhD
mailto: erinm.hodg...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] as.Date() function

2018-08-19 Thread philipsm

Thanks Erin and Jim. You have indeed solved my problem.

Philip


Quoting Erin Hodgess :


Hi Philip:

Here is something to consider:


#potential solution:
sta <- paste(st,"-01",sep="")
st1 <- as.Date(sta, format=("%Y-%m-%d"))
print(st1)

[1] "1961-01-01" "1961-04-01" "1983-02-01"


Hope this helps!
Erin

Erin Hodgess, PhD
mailto: erinm.hodg...@gmail.com


On Sun, Aug 19, 2018 at 3:25 PM  wrote:


I am having trouble with what must be a very simple problem. Here is a
reproducible example:

library(lubridate)
st <- c("1961-01","1961-04","1983-02")
print(st)
#[1] "1961-01" "1961-04" "1983-02"
st1 <- as.Date(st, format=("%Y-%m"))
print(st1)
#[1] NA NA NA

Why the heck am I getting three NAs instead of three Dates?I have
studied the R documentation for as.Date() and it has not turned on the
light bulb for me.

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



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


Re: [R] as.Date() function

2018-08-19 Thread Jim Lemon
Hi Phillip,
Jose has the correct answer. You probably missed this sentence in the
"Note" section of the help page:

"If the date string does not specify the date completely, the returned
answer may be system-specific."

In your case, the function throws up its hands and returns NA as you
haven't specified a date.

Jim

On Mon, Aug 20, 2018 at 7:20 AM,   wrote:
> I am having trouble with what must be a very simple problem. Here is a
> reproducible example:
>
> library(lubridate)
> st <- c("1961-01","1961-04","1983-02")
> print(st)
> #[1] "1961-01" "1961-04" "1983-02"
> st1 <- as.Date(st, format=("%Y-%m"))
> print(st1)
> #[1] NA NA NA
>
> Why the heck am I getting three NAs instead of three Dates?I have studied
> the R documentation for as.Date() and it has not turned on the light bulb
> for me.
>
> __
> R-help@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.

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


Re: [R] as.Date() function

2018-08-19 Thread José María Mateos
On Sun, Aug 19, 2018 at 05:20:29PM -0400, phili...@cpanel1.stormweb.net wrote:
> Why the heck am I getting three NAs instead of three Dates?I have
> studied the R documentation for as.Date() and it has not turned on
> the light bulb for me.

I haven't encountered this problem before, but in my mind, if you want a 
date, you'll also need to specify the day. Only year and month won't cut 
it.

Cheers,

-- 
José María (Chema) Mateos
https://rinzewind.org/blog-es || https://rinzewind.org/blog-en

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


Re: [R] as.Date() function

2018-08-19 Thread Erin Hodgess
Hi Philip:

Here is something to consider:

> #potential solution:
> sta <- paste(st,"-01",sep="")
> st1 <- as.Date(sta, format=("%Y-%m-%d"))
> print(st1)
[1] "1961-01-01" "1961-04-01" "1983-02-01"


Hope this helps!
Erin

Erin Hodgess, PhD
mailto: erinm.hodg...@gmail.com


On Sun, Aug 19, 2018 at 3:25 PM  wrote:

> I am having trouble with what must be a very simple problem. Here is a
> reproducible example:
>
> library(lubridate)
> st <- c("1961-01","1961-04","1983-02")
> print(st)
> #[1] "1961-01" "1961-04" "1983-02"
> st1 <- as.Date(st, format=("%Y-%m"))
> print(st1)
> #[1] NA NA NA
>
> Why the heck am I getting three NAs instead of three Dates?I have
> studied the R documentation for as.Date() and it has not turned on the
> light bulb for me.
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

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


Re: [R] as.Date and Legend in a plot

2018-06-22 Thread MacQueen, Don via R-help
What David Winsemius said, plus:

Does
  legend('topleft', c("Climax", "Thule", "Sopo"), lty = 1, col = 
("black","red","blue"))
not work?

It should, which will illustrate that you CAN add a legend to the plot.

The x,y that you supply to legend must be values that are within the x,y range 
of the plot. Type
   par()$usr
to see what that range is, and I think you will see that 1998 is not within the 
plot range.

David showed you how to supply legend with an x value that is, we assume, 
within the plot range.

You *should* have had an error on your second try:

> as.Date(1998-02-10)
Error in as.Date.numeric(1998 - 2 - 10) : 'origin' must be supplied

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
 
 

On 6/22/18, 12:12 PM, "R-help on behalf of Ogbos Okike" 
 wrote:

Dear Contributors,

I am surprised that I cannot add legend to a certain plot. Although the
x-axis indicates years, the actual data was in year, month and day format.
I then used as.Date to play around and get what I am looking for. I am,
however, worried that I cannot add legend to the plot no matter how I
tried. Looking at the axis, I tried:
legend(1998,3, c("Climax", "Thule", "Sopo"), lty = 1, col =
c("black","red","blue")). I also tried:

legend(as.Date(1998-02-10),3, c("Climax", "Thule", "Sopo"), lty = 1, col =
c("black","red","blue"))
but no result and no error.

I have attached the plot in case it will assist in your suggestions.

Many thanks for your time.

Ogbos
__
R-help@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.


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


Re: [R] as.Date and Legend in a plot

2018-06-22 Thread David Winsemius


> On Jun 22, 2018, at 12:12 PM, Ogbos Okike  wrote:
> 
> Dear Contributors,
> 
> I am surprised that I cannot add legend to a certain plot. Although the
> x-axis indicates years, the actual data was in year, month and day format.
> I then used as.Date to play around and get what I am looking for. I am,
> however, worried that I cannot add legend to the plot no matter how I
> tried. Looking at the axis, I tried:
> legend(1998,3, c("Climax", "Thule", "Sopo"), lty = 1, col =
> c("black","red","blue")). I also tried:
> 
> legend(as.Date(1998-02-10),

I don't think you understand the difference between character values and 
numeric values. Thr using 

as.Date("1998-02-10")


> 3, c("Climax", "Thule", "Sopo"), lty = 1, col =
> c("black","red","blue"))
> but no result and no error.
> 
> I have attached the plot in case it will assist in your suggestions.
> 
> Many thanks for your time.
> 
> Ogbos
> __
> R-help@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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

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


Re: [R] as.Date: fixed

2016-04-18 Thread Ogbos Okike
Dear All,
Many thanks for bailing me out.
Ogbos
On Apr 18, 2016 9:07 PM, "David Winsemius"  wrote:

>
> > On Apr 18, 2016, at 10:44 AM, Ogbos Okike 
> wrote:
> >
> > Dear ALL,
> > Thank you so much for your contributions.
> > I have made some progress. Below is a simple script I gleaned from
> > your kind responses:
> > Sys.setenv(TZ="Etc/GMT")
> > dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
> > times <- c("23:0:0", "22:0:0", "01:00:00", "18:0:0", "16:0:0")
> > x <- paste(dates, times)
> > aa<-strptime(x, "%m/%d/%y %H:%M:%S")
> > bb<-1:5
> > plot(aa, bb)
> >
> > I tried plotting my result and I got what I am looking for. I think I
> > am almost there.
> >
> > I am, however, stuck here. My data is a large file and the form
> > differs a little from the example I used. The quotation marks in both
> > date and time is my headache now. Such inverted commas are not in my
> > data. I can with awk transform my data to get exactly something like
> > dd/mm/yy. But I wont know how to make the data appear in quotation
> > mark in R.
>
> There are not any quotation marks in an R object that is displayed as
> "02/27/92". The quotation marks are just added by the print function to
> make it clear to the user that it is a character value.
>
> If you read such values in with read.table they would automatically be
> interpreted as character values and then converted to factor class (which
> you do not want). Read up on the use in the read.* functions for colClasses
> and stringsAsFactors to safely input character values.
> --
> David.
>
> > I will once more be glad for any more help.
> > Ogbos
> >
> > PS: I am still afraid of this forum. Please direct me to the right
> > forum if this is not ok. Thanks again.
> >
> >
> > On 4/18/16, peter dalgaard  wrote:
> >> The most important thing is that Date objects by definition do not
> include
> >> time of day. You want to look at ISOdatetime() and as.POSIXct()
> instead. And
> >> beware daylight savings time issues.
> >>
> >> -pd
> >>
> >> On 18 Apr 2016, at 15:09 , Ogbos Okike 
> wrote:
> >>
> >>> Dear All,
> >>>
> >>> I have a data set containing year, month, day and counts as shown
> below:
> >>> data <- read.table("data.txt", col.names = c("year", "month", "day",
> >>> "counts"))
> >>> Using the formula below, I converted the data to as date and plotted.
> >>>
> >>> new.century <- data$year < 70
> >>>
> >>> data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> >>>
> >>> data$date <- as.Date(ISOdate(data$year, data$month, data$day))
> >>>
> >>> The form of the data is:
> >>> 16 1 19 9078
> >>> 16 1 20 9060
> >>> 16 1 21 9090
> >>> 16 1 22 9080
> >>> 16 1 23 9121
> >>> 16 1 24 9199
> >>> 16 1 25 9289
> >>> 16 1 26 9285
> >>> 16 1 27 9245
> >>> 16 1 28 9223
> >>> 16 1 29 9298
> >>> 16 1 30 9327
> >>> 16 1 31 9365
> >>>
> >>> Now, I wish to include time (hour) in my data. The new data is of the
> >>> form:
> >>> 05 01 06 143849
> >>> 05 01 06 153845
> >>> 05 01 06 163836
> >>> 05 01 06 173847
> >>> 05 01 06 183850
> >>> 05 01 06 193872
> >>> 05 01 06 203849
> >>> 05 01 06 213860
> >>> 05 01 06 223868
> >>> 05 01 06 233853
> >>> 05 01 07 003839
> >>> 05 01 07 013842
> >>> 05 01 07 023843
> >>> 05 01 07 033865
> >>> 05 01 07 043879
> >>> 05 01 07 053876
> >>> 05 01 07 063867
> >>> 05 01 07 073887
> >>>
> >>> I now read the data as:
> >>> data <- read.table("data.txt", col.names = c("year", "month", "day",
> >>> "counts", "hour")) and also included hour in data$date <-
> >>> as.Date(ISOdate(data$year, data$month, data$day))
> >>> i.e data$date <- as.Date(ISOdate(data$year, data$month, data$day,
> >>> data$hour)).
> >>>
> >>> However, these did not work.
> >>>
> >>> Can you please assist be on how to get this date and time in the right
> >>> format. The right format I got without hour looks like : 2005-12-29"
> >>> "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> >>> [8696] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> >>> [8701] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> >>> [8706] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> >>>
> >>> I used this in my plot. Please I want this format to include hour.
> >>>
> >>> Many thanks for your help. I am just a newbe. I am not sure if this
> >>> forum is the right one. After registration, I tried to post to Nabble
> >>> forum where I registered but could not succeed.
> >>>
> >>> If there is a mistake, please help/direct me to the right forum.
> >>>
> >>> Best regards
> >>> Ogbos
> >>>
> >>> __
> >>> R-help@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.
> >>
> >> --
> >> Peter Dalgaa

Re: [R] as.Date

2016-04-18 Thread David Winsemius

> On Apr 18, 2016, at 10:44 AM, Ogbos Okike  wrote:
> 
> Dear ALL,
> Thank you so much for your contributions.
> I have made some progress. Below is a simple script I gleaned from
> your kind responses:
> Sys.setenv(TZ="Etc/GMT")
> dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
> times <- c("23:0:0", "22:0:0", "01:00:00", "18:0:0", "16:0:0")
> x <- paste(dates, times)
> aa<-strptime(x, "%m/%d/%y %H:%M:%S")
> bb<-1:5
> plot(aa, bb)
> 
> I tried plotting my result and I got what I am looking for. I think I
> am almost there.
> 
> I am, however, stuck here. My data is a large file and the form
> differs a little from the example I used. The quotation marks in both
> date and time is my headache now. Such inverted commas are not in my
> data. I can with awk transform my data to get exactly something like
> dd/mm/yy. But I wont know how to make the data appear in quotation
> mark in R.

There are not any quotation marks in an R object that is displayed as 
"02/27/92". The quotation marks are just added by the print function to make it 
clear to the user that it is a character value. 

If you read such values in with read.table they would automatically be 
interpreted as character values and then converted to factor class (which you 
do not want). Read up on the use in the read.* functions for colClasses and 
stringsAsFactors to safely input character values.
-- 
David.

> I will once more be glad for any more help.
> Ogbos
> 
> PS: I am still afraid of this forum. Please direct me to the right
> forum if this is not ok. Thanks again.
> 
> 
> On 4/18/16, peter dalgaard  wrote:
>> The most important thing is that Date objects by definition do not include
>> time of day. You want to look at ISOdatetime() and as.POSIXct() instead. And
>> beware daylight savings time issues.
>> 
>> -pd
>> 
>> On 18 Apr 2016, at 15:09 , Ogbos Okike  wrote:
>> 
>>> Dear All,
>>> 
>>> I have a data set containing year, month, day and counts as shown below:
>>> data <- read.table("data.txt", col.names = c("year", "month", "day",
>>> "counts"))
>>> Using the formula below, I converted the data to as date and plotted.
>>> 
>>> new.century <- data$year < 70
>>> 
>>> data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
>>> 
>>> data$date <- as.Date(ISOdate(data$year, data$month, data$day))
>>> 
>>> The form of the data is:
>>> 16 1 19 9078
>>> 16 1 20 9060
>>> 16 1 21 9090
>>> 16 1 22 9080
>>> 16 1 23 9121
>>> 16 1 24 9199
>>> 16 1 25 9289
>>> 16 1 26 9285
>>> 16 1 27 9245
>>> 16 1 28 9223
>>> 16 1 29 9298
>>> 16 1 30 9327
>>> 16 1 31 9365
>>> 
>>> Now, I wish to include time (hour) in my data. The new data is of the
>>> form:
>>> 05 01 06 143849
>>> 05 01 06 153845
>>> 05 01 06 163836
>>> 05 01 06 173847
>>> 05 01 06 183850
>>> 05 01 06 193872
>>> 05 01 06 203849
>>> 05 01 06 213860
>>> 05 01 06 223868
>>> 05 01 06 233853
>>> 05 01 07 003839
>>> 05 01 07 013842
>>> 05 01 07 023843
>>> 05 01 07 033865
>>> 05 01 07 043879
>>> 05 01 07 053876
>>> 05 01 07 063867
>>> 05 01 07 073887
>>> 
>>> I now read the data as:
>>> data <- read.table("data.txt", col.names = c("year", "month", "day",
>>> "counts", "hour")) and also included hour in data$date <-
>>> as.Date(ISOdate(data$year, data$month, data$day))
>>> i.e data$date <- as.Date(ISOdate(data$year, data$month, data$day,
>>> data$hour)).
>>> 
>>> However, these did not work.
>>> 
>>> Can you please assist be on how to get this date and time in the right
>>> format. The right format I got without hour looks like : 2005-12-29"
>>> "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>>> [8696] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>>> [8701] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>>> [8706] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>>> 
>>> I used this in my plot. Please I want this format to include hour.
>>> 
>>> Many thanks for your help. I am just a newbe. I am not sure if this
>>> forum is the right one. After registration, I tried to post to Nabble
>>> forum where I registered but could not succeed.
>>> 
>>> If there is a mistake, please help/direct me to the right forum.
>>> 
>>> Best regards
>>> Ogbos
>>> 
>>> __
>>> R-help@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.
>> 
>> --
>> Peter Dalgaard, Professor,
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Office: A 4.23
>> Email: pd@cbs.dk  Priv: pda...@gmail.com
>> 
>> 
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat

Re: [R] as.Date

2016-04-18 Thread Ogbos Okike
Dear ALL,
Thank you so much for your contributions.
I have made some progress. Below is a simple script I gleaned from
your kind responses:
Sys.setenv(TZ="Etc/GMT")
dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
 times <- c("23:0:0", "22:0:0", "01:00:00", "18:0:0", "16:0:0")
 x <- paste(dates, times)
 aa<-strptime(x, "%m/%d/%y %H:%M:%S")
bb<-1:5
plot(aa, bb)

I tried plotting my result and I got what I am looking for. I think I
am almost there.

I am, however, stuck here. My data is a large file and the form
differs a little from the example I used. The quotation marks in both
date and time is my headache now. Such inverted commas are not in my
data. I can with awk transform my data to get exactly something like
dd/mm/yy. But I wont know how to make the data appear in quotation
mark in R. I will once more be glad for any more help.
Ogbos

PS: I am still afraid of this forum. Please direct me to the right
forum if this is not ok. Thanks again.


On 4/18/16, peter dalgaard  wrote:
> The most important thing is that Date objects by definition do not include
> time of day. You want to look at ISOdatetime() and as.POSIXct() instead. And
> beware daylight savings time issues.
>
> -pd
>
> On 18 Apr 2016, at 15:09 , Ogbos Okike  wrote:
>
>> Dear All,
>>
>> I have a data set containing year, month, day and counts as shown below:
>> data <- read.table("data.txt", col.names = c("year", "month", "day",
>> "counts"))
>> Using the formula below, I converted the data to as date and plotted.
>>
>> new.century <- data$year < 70
>>
>> data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
>>
>> data$date <- as.Date(ISOdate(data$year, data$month, data$day))
>>
>> The form of the data is:
>> 16 1 19 9078
>> 16 1 20 9060
>> 16 1 21 9090
>> 16 1 22 9080
>> 16 1 23 9121
>> 16 1 24 9199
>> 16 1 25 9289
>> 16 1 26 9285
>> 16 1 27 9245
>> 16 1 28 9223
>> 16 1 29 9298
>> 16 1 30 9327
>> 16 1 31 9365
>>
>> Now, I wish to include time (hour) in my data. The new data is of the
>> form:
>> 05 01 06 143849
>> 05 01 06 153845
>> 05 01 06 163836
>> 05 01 06 173847
>> 05 01 06 183850
>> 05 01 06 193872
>> 05 01 06 203849
>> 05 01 06 213860
>> 05 01 06 223868
>> 05 01 06 233853
>> 05 01 07 003839
>> 05 01 07 013842
>> 05 01 07 023843
>> 05 01 07 033865
>> 05 01 07 043879
>> 05 01 07 053876
>> 05 01 07 063867
>> 05 01 07 073887
>>
>> I now read the data as:
>> data <- read.table("data.txt", col.names = c("year", "month", "day",
>> "counts", "hour")) and also included hour in data$date <-
>> as.Date(ISOdate(data$year, data$month, data$day))
>> i.e data$date <- as.Date(ISOdate(data$year, data$month, data$day,
>> data$hour)).
>>
>> However, these did not work.
>>
>> Can you please assist be on how to get this date and time in the right
>> format. The right format I got without hour looks like : 2005-12-29"
>> "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>> [8696] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>> [8701] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>> [8706] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>>
>> I used this in my plot. Please I want this format to include hour.
>>
>> Many thanks for your help. I am just a newbe. I am not sure if this
>> forum is the right one. After registration, I tried to post to Nabble
>> forum where I registered but could not succeed.
>>
>> If there is a mistake, please help/direct me to the right forum.
>>
>> Best regards
>> Ogbos
>>
>> __
>> R-help@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.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>

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


Re: [R] as.Date

2016-04-18 Thread Jeff Newmiller
Date data cannot represent hour data. You need to use POSIXct or perhaps the 
chron class from the chron package. 

To use POSIXct, use ISOdatetime instead of ISOdate. Also be careful which 
timezone you have set as default (in most operating systems calling 
Sys.setenv(TZ="Etc/GMT") or similar will get you started) when you invoke 
ISOdatetime, since daylight savings can complicate things. Of course if 
daylight savings is built into your data already then  you are better off 
choosing a timezone that understands that. See ?DateTimeClasses.
-- 
Sent from my phone. Please excuse my brevity.

On April 18, 2016 6:09:50 AM PDT, Ogbos Okike  wrote:
>Dear All,
>
>I have a data set containing year, month, day and counts as shown
>below:
>data <- read.table("data.txt", col.names = c("year", "month", "day",
>"counts"))
>Using the formula below, I converted the data to as date and plotted.
>
>new.century <- data$year < 70
>
>data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
>
>data$date <- as.Date(ISOdate(data$year, data$month, data$day))
>
>The form of the data is:
>16 1 19 9078
>16 1 20 9060
>16 1 21 9090
>16 1 22 9080
>16 1 23 9121
>16 1 24 9199
>16 1 25 9289
>16 1 26 9285
>16 1 27 9245
>16 1 28 9223
>16 1 29 9298
>16 1 30 9327
>16 1 31 9365
>
>Now, I wish to include time (hour) in my data. The new data is of the
>form:
>05 01 06 143849
>05 01 06 153845
>05 01 06 163836
>05 01 06 173847
>05 01 06 183850
>05 01 06 193872
>05 01 06 203849
>05 01 06 213860
>05 01 06 223868
>05 01 06 233853
>05 01 07 003839
>05 01 07 013842
>05 01 07 023843
>05 01 07 033865
>05 01 07 043879
>05 01 07 053876
>05 01 07 063867
>05 01 07 073887
>
>I now read the data as:
>data <- read.table("data.txt", col.names = c("year", "month", "day",
>"counts", "hour")) and also included hour in data$date <-
>as.Date(ISOdate(data$year, data$month, data$day))
>i.e data$date <- as.Date(ISOdate(data$year, data$month, data$day,
>data$hour)).
>
>However, these did not work.
>
>Can you please assist be on how to get this date and time in the right
>format. The right format I got without hour looks like : 2005-12-29"
>"2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>[8696] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>[8701] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>[8706] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>
>I used this in my plot. Please I want this format to include hour.
>
>Many thanks for your help. I am just a newbe. I am not sure if this
>forum is the right one. After registration, I tried to post to Nabble
>forum where I registered but could not succeed.
>
>If there is a mistake, please help/direct me to the right forum.
>
>Best regards
>Ogbos
>
>__
>R-help@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.

[[alternative HTML version deleted]]

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


Re: [R] as.Date

2016-04-18 Thread PIKAL Petr
Hi

AFAIK as.Date does not accept hours. Although it is not explicitly written in 
help page, the name as.Date seems to me clear enough that it works only with 
dates.

If you want to use hours, minutes ... you should use strptime for converting 
your values to valid date_time object.

And you should also use ISOdatetime conversion function to use hours etc. in 
your commands.

Cheers
Petr


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ogbos
> Okike
> Sent: Monday, April 18, 2016 3:10 PM
> To: r-help@r-project.org
> Subject: [R] as.Date
>
> Dear All,
>
> I have a data set containing year, month, day and counts as shown below:
> data <- read.table("data.txt", col.names = c("year", "month", "day",
> "counts")) Using the formula below, I converted the data to as date and
> plotted.
>
> new.century <- data$year < 70
>
> data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
>
> data$date <- as.Date(ISOdate(data$year, data$month, data$day))
>
> The form of the data is:
> 16 1 19 9078
> 16 1 20 9060
> 16 1 21 9090
> 16 1 22 9080
> 16 1 23 9121
> 16 1 24 9199
> 16 1 25 9289
> 16 1 26 9285
> 16 1 27 9245
> 16 1 28 9223
> 16 1 29 9298
> 16 1 30 9327
> 16 1 31 9365
>
> Now, I wish to include time (hour) in my data. The new data is of the form:
> 05 01 06 143849
> 05 01 06 153845
> 05 01 06 163836
> 05 01 06 173847
> 05 01 06 183850
> 05 01 06 193872
> 05 01 06 203849
> 05 01 06 213860
> 05 01 06 223868
> 05 01 06 233853
> 05 01 07 003839
> 05 01 07 013842
> 05 01 07 023843
> 05 01 07 033865
> 05 01 07 043879
> 05 01 07 053876
> 05 01 07 063867
> 05 01 07 073887
>
> I now read the data as:
> data <- read.table("data.txt", col.names = c("year", "month", "day",
> "counts", "hour")) and also included hour in data$date <-
> as.Date(ISOdate(data$year, data$month, data$day)) i.e data$date <-
> as.Date(ISOdate(data$year, data$month, data$day, data$hour)).
>
> However, these did not work.
>
> Can you please assist be on how to get this date and time in the right format.
> The right format I got without hour looks like : 2005-12-29"
> "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> [8696] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> [8701] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> [8706] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
>
> I used this in my plot. Please I want this format to include hour.
>
> Many thanks for your help. I am just a newbe. I am not sure if this forum is
> the right one. After registration, I tried to post to Nabble forum where I
> registered but could not succeed.
>
> If there is a mistake, please help/direct me to the right forum.
>
> Best regards
> Ogbos
>
> __
> R-help@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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for

Re: [R] as.Date

2016-04-18 Thread peter dalgaard
The most important thing is that Date objects by definition do not include time 
of day. You want to look at ISOdatetime() and as.POSIXct() instead. And beware 
daylight savings time issues.

-pd

On 18 Apr 2016, at 15:09 , Ogbos Okike  wrote:

> Dear All,
> 
> I have a data set containing year, month, day and counts as shown below:
> data <- read.table("data.txt", col.names = c("year", "month", "day", 
> "counts"))
> Using the formula below, I converted the data to as date and plotted.
> 
> new.century <- data$year < 70
> 
> data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> 
> data$date <- as.Date(ISOdate(data$year, data$month, data$day))
> 
> The form of the data is:
> 16 1 19 9078
> 16 1 20 9060
> 16 1 21 9090
> 16 1 22 9080
> 16 1 23 9121
> 16 1 24 9199
> 16 1 25 9289
> 16 1 26 9285
> 16 1 27 9245
> 16 1 28 9223
> 16 1 29 9298
> 16 1 30 9327
> 16 1 31 9365
> 
> Now, I wish to include time (hour) in my data. The new data is of the form:
> 05 01 06 143849
> 05 01 06 153845
> 05 01 06 163836
> 05 01 06 173847
> 05 01 06 183850
> 05 01 06 193872
> 05 01 06 203849
> 05 01 06 213860
> 05 01 06 223868
> 05 01 06 233853
> 05 01 07 003839
> 05 01 07 013842
> 05 01 07 023843
> 05 01 07 033865
> 05 01 07 043879
> 05 01 07 053876
> 05 01 07 063867
> 05 01 07 073887
> 
> I now read the data as:
> data <- read.table("data.txt", col.names = c("year", "month", "day",
> "counts", "hour")) and also included hour in data$date <-
> as.Date(ISOdate(data$year, data$month, data$day))
> i.e data$date <- as.Date(ISOdate(data$year, data$month, data$day, data$hour)).
> 
> However, these did not work.
> 
> Can you please assist be on how to get this date and time in the right
> format. The right format I got without hour looks like : 2005-12-29"
> "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> [8696] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> [8701] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> [8706] "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29" "2005-12-29"
> 
> I used this in my plot. Please I want this format to include hour.
> 
> Many thanks for your help. I am just a newbe. I am not sure if this
> forum is the right one. After registration, I tried to post to Nabble
> forum where I registered but could not succeed.
> 
> If there is a mistake, please help/direct me to the right forum.
> 
> Best regards
> Ogbos
> 
> __
> R-help@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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] as.Date woes

2014-08-20 Thread Peter Langfelder
Never mind... the solution was to read the source code of
as.Date.character. It turns out the default format="" is meaningless.
If 'format' is not given in the call to as.Date, it is NOT assumed to
be "", and the function gives very different results from a call where
the argument format="" is given. G...

Peter

On Wed, Aug 20, 2014 at 11:56 AM, Peter Langfelder
 wrote:
> Hi all,
>
> I have recently started working with Date objects and find the
> experience unsettling, to put it mildly.
>
> The help for as.Date says, in part:
>
>  ## S3 method for class 'character'
>  as.Date(x, format = "", ...)
>
>x: An object to be converted.
>
>   format: A character string.  If not specified, it will try
>   ‘"%Y-%m-%d"’ then ‘"%Y/%m/%d"’ on the first non-‘NA’ element,
>   and give an error if neither works.
>
>
> If I read this correctly,
>
> as.Date("2012-04-30") and
> as.Date("2012-04-30", format = "")
>
> should give the same results, but they don't:
>
>> as.Date("2012-04-30")
> [1] "2012-04-30"
>> as.Date("2012-04-30", format = "")
> [1] "2014-08-20"
>
> Note the latter gives today's date, without any warning or message.
>
> What method is called in the latter case?
>
> Another issue I am running into, that is probably connected to the
> 'format' argument above, is trying to convert a numeric or character
> in the same call. Basically, I would like to call
>
> as.Date(object, format = "", origin = "1970-1-1")
>
> where object can be a Date, numeric or character, in the hope that the
> appropriate method will be selected and will ignore unnecessary
> arguments.
>
> Here's what I get:
>
>> as.Date( as.numeric(Sys.Date()), origin = "1970-1-1")
> [1] "2014-08-20"    Correct
>> as.Date( as.numeric(Sys.Date()), origin = "1970-1-1", format = "")
> [1] "2059-04-08"    ???
>
> Excuse the coarse language, but WTF??? The first call confirms that
> the origin is specified correctly, and the second gives a date removed
> from the origin by twice the number of days than the actual input??
>
>> as.numeric(Sys.Date())
> [1] 16302
>> as.numeric(as.Date( as.numeric(Sys.Date()), origin = "1970-1-1"))
> [1] 16302
>> as.numeric(as.Date( as.numeric(Sys.Date()), origin = "1970-1-1", format = 
>> ""))
> [1] 32604
>
>
> Thanks in advance for any pointers!
>
> Peter
>
> PS: I know my R is not the most up to date, but I haven't found
> anything about Date mentioned in the changelog for the 3.x series.
>
>
>> sessionInfo()
> R version 3.0.2 Patched (2013-10-08 r64039)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.utf8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8
>  [5] LC_MONETARY=en_US.utf8LC_MESSAGES=en_US.utf8
>  [7] LC_PAPER=en_US.utf8   LC_NAME=C
>  [9] LC_ADDRESS=C  LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base

__
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] as.Date(Sys.time()) returns tomorrow !

2014-06-19 Thread ce

I guessed it too, but my command 

as.Date(Sys.time(),tz="EDT")
[1] "2014-06-20"

doesn't give warning message you got for PDT . I thought EDT was a valid TZ !
Now I changed it to :
> as.Date(Sys.time(),tz="America/New_York")
[1] "2014-06-19"

Thanks. 

-Original Message-
From: "William Dunlap" [wdun...@tibco.com]
Date: 06/19/2014 11:10 PM
To: "ce" 
CC: r-help@r-project.org
Subject: Re: [R] as.Date(Sys.time()) returns tomorrow !

Is it a time zone issue?  I get:

R> Sys.time()
[1] "2014-06-19 20:09:25 PDT"
R> as.Date(Sys.time())
[1] "2014-06-20"
R> as.Date(Sys.time(),tz="US/Pacific")
[1] "2014-06-19"
R> as.Date(Sys.time(),tz="PDT")
[1] "2014-06-20"
Warning message:
In as.POSIXlt.POSIXct(x, tz = tz) : unknown timezone 'PDT'
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jun 19, 2014 at 7:22 PM, ce  wrote:
> Dear all,
>
>> Sys.time()
> [1] "2014-06-19 22:19:17.976818 EDT"
>
>> as.Date(Sys.time())
> [1] "2014-06-20"
>>
>
>
> why this happens ?
>
> __
> 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.

__
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] as.Date(Sys.time()) returns tomorrow !

2014-06-19 Thread William Dunlap
Is it a time zone issue?  I get:

R> Sys.time()
[1] "2014-06-19 20:09:25 PDT"
R> as.Date(Sys.time())
[1] "2014-06-20"
R> as.Date(Sys.time(),tz="US/Pacific")
[1] "2014-06-19"
R> as.Date(Sys.time(),tz="PDT")
[1] "2014-06-20"
Warning message:
In as.POSIXlt.POSIXct(x, tz = tz) : unknown timezone 'PDT'
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jun 19, 2014 at 7:22 PM, ce  wrote:
> Dear all,
>
>> Sys.time()
> [1] "2014-06-19 22:19:17.976818 EDT"
>
>> as.Date(Sys.time())
> [1] "2014-06-20"
>>
>
>
> why this happens ?
>
> __
> 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.

__
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] as.Date converts to NA

2014-03-09 Thread arun
Hi,

Check for the additional "%" in your code "%d%".
 as.Date(strDates,"%m/%d/%Y")
#[1] "1965-01-05" "1975-08-16"
A.K.




On Sunday, March 9, 2014 12:16 PM, Hermann Norpois  wrote:
Hello,
I have some problems with as.Date.

strDates <- c ("01/05/1965", "08/16/1975")
dates <- as.Date (strDates, "%m/%d%/%Y")
dates
[1] NA NA # I expected my dates. What was going wrong?

Thanks
Hermann

    [[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.


__
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] as.Date converts to NA

2014-03-09 Thread Achim Zeileis

On Sun, 9 Mar 2014, Hermann Norpois wrote:


Hello,
I have some problems with as.Date.

strDates <- c ("01/05/1965", "08/16/1975")
dates <- as.Date (strDates, "%m/%d%/%Y")

  
Instead of "%d%" just "%d":

R> as.Date(strDates, "%m/%d/%Y")
[1] "1965-01-05" "1975-08-16"



dates
[1] NA NA # I expected my dates. What was going wrong?

Thanks
Hermann

[[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.



__
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] as.Date converts to NA

2014-03-09 Thread Uwe Ligges



On 09.03.2014 11:34, Hermann Norpois wrote:

Hello,
I have some problems with as.Date.

strDates <- c ("01/05/1965", "08/16/1975")
dates <- as.Date (strDates, "%m/%d%/%Y")

^
Remove the "%" after the "d".

Best,
Uwe Ligges



dates
[1] NA NA # I expected my dates. What was going wrong?

Thanks
Hermann

[[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.



__
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] as.Date with characters error

2013-07-30 Thread Liz Hare

Oh! Thank you so much! Sorry to have bothered everyone with this!

Liz


On 7/30/2013 12:16 PM, arun wrote:

Hi,
Did you checked after removing "e" from "formate"?

ortho$test.dat <- as.Date(ortho$xray.date, formate="%d-%b-%y")

A.K.


- Original Message -
From: Liz Hare 
To: r-help@r-project.org
Cc:
Sent: Tuesday, July 30, 2013 12:00 PM
Subject: [R] as.Date with characters error

Hello,

I'm trying to convert dates in the format dd-mmm-yy using as.Date.
I have two columns like this, and it works on one but not on the other.


options(stringsAsFactors=FALSE)
ortho <- read.csv("test1.csv", header=TRUE, nrows=10)
ortho

 DogID BirthDate xray.date
1  11877 23-Aug-87 15-Feb-88
2  11877 23-Aug-87 15-Feb-88
3   3599 21-Feb-87 21-Feb-88
4   3599 21-Feb-87 21-Feb-88
5   3599 21-Feb-87 21-Feb-88
6   3599 21-Feb-87 21-Feb-88
7   3599 21-Feb-87 21-Feb-88
8   9563 29-Jun-87 29-Jun-88
9   9563 29-Jun-87 29-Jun-88
10  9563 29-Jun-87 29-Jun-88

ortho$bdat <- as.Date(ortho$BirthDate, format="%d-%b-%y")
ortho$bdat

   [1] "1987-08-23" "1987-08-23" "1987-02-21" "1987-02-21" "1987-02-21"
   [6] "1987-02-21" "1987-02-21" "1987-06-29" "1987-06-29" "1987-06-29"

ortho$test.dat <- as.Date(ortho$xray.date, formate="%d-%b-%y")

Error in charToDate(x) :
character string is not in a standard unambiguous format

sessionInfo()

R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base




Does anyone have a guess about what's going on? I've googled for this
error but haven't found any where the problem is with this type of
conversion.

Thanks,
Liz



__
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] as.Date with characters error

2013-07-30 Thread arun
Hi,
Did you checked after removing "e" from "formate"?

ortho$test.dat <- as.Date(ortho$xray.date, formate="%d-%b-%y")
 
A.K.


- Original Message -
From: Liz Hare 
To: r-help@r-project.org
Cc: 
Sent: Tuesday, July 30, 2013 12:00 PM
Subject: [R] as.Date with characters error

Hello,

I'm trying to convert dates in the format dd-mmm-yy using as.Date.
I have two columns like this, and it works on one but not on the other.

> options(stringsAsFactors=FALSE)
> ortho <- read.csv("test1.csv", header=TRUE, nrows=10)
> ortho
    DogID BirthDate xray.date
1  11877 23-Aug-87 15-Feb-88
2  11877 23-Aug-87 15-Feb-88
3   3599 21-Feb-87 21-Feb-88
4   3599 21-Feb-87 21-Feb-88
5   3599 21-Feb-87 21-Feb-88
6   3599 21-Feb-87 21-Feb-88
7   3599 21-Feb-87 21-Feb-88
8   9563 29-Jun-87 29-Jun-88
9   9563 29-Jun-87 29-Jun-88
10  9563 29-Jun-87 29-Jun-88
> ortho$bdat <- as.Date(ortho$BirthDate, format="%d-%b-%y")
> ortho$bdat
  [1] "1987-08-23" "1987-08-23" "1987-02-21" "1987-02-21" "1987-02-21"
  [6] "1987-02-21" "1987-02-21" "1987-06-29" "1987-06-29" "1987-06-29"
> ortho$test.dat <- as.Date(ortho$xray.date, formate="%d-%b-%y")
Error in charToDate(x) :
   character string is not in a standard unambiguous format
> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
>

Does anyone have a guess about what's going on? I've googled for this 
error but haven't found any where the problem is with this type of 
conversion.

Thanks,
Liz

-- 
Liz Hare PhD
Dog Genetics LLC
dogg...@earthlink.net
http://www.doggenetics.com

__
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.


__
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] as.date not reading Hour/Minute am/pm Data

2013-04-15 Thread arun


Hi,
Try:
x<- c("2/26/13 11:59 PM", "2/25/13 10:25 AM")
strptime(x,"%m/%d/%y %I:%M %p")
#[1] "2013-02-26 23:59:00" "2013-02-25 10:25:00"

#or
library(lubridate)
parse_date_time(x,"%m/%d/%y %I:%M %p")
# 2 parsed with %m/%d/%y %I:%M %p
#[1] "2013-02-26 23:59:00 UTC" "2013-02-25 10:25:00 UTC"
A.K.


>I'm a newbie to R but not programming.   
>
>I've researched online and through this forum and am unsure of 
why I'm not getting a as.date object to only store a limited amount of 
data.  The date >is in the format of: 2/26/13 11:59 PM in a .csv file 
with over 5000 data points.  My as.date function reads: 
>
>> gld <- read.csv("c:/data/gbpdata.csv", stringsAsFactors=F) 
>> gld_dates <- as.Date(gld[,1], format="%m/%d/%y %H:%M %p") 
>> gld_dates: 
>
>[36775] "2013-04-03" "2013-04-03" "2013-04-03" "2013-04-03" "2013-04-03" 
>"2013-04-03" "2013-04-03" "2013-04-03" "2013-04-03" 
>
>What am I doing wrong?  Thanks in advance for your replies.

__
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] as.Date to as.POSIXct

2012-12-25 Thread arun
Hi,

You should have provided a reproducible example.
To convert in general, ?as.POSIXct()

A.K.




- Original Message -
From: Antonio Rodriges 
To: r-help@r-project.org
Cc: 
Sent: Tuesday, December 25, 2012 7:28 AM
Subject: [R] as.Date to as.POSIXct

Hello,

I have converted some UNIX time stamps with as.Date as follows

dates_unix <- seq(
             as.Date(convertTimeToString(timeStart)),
             length = length(data),
             by="1 mon")

and now I would like to convert "dates_unix" from type Date to type POSIXct

How can I do that?


Thanks

__
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.


__
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] as.date: do not know how to convert 'test[1]' to class "Date"

2012-08-01 Thread Rui Barradas

Hello,

Try reading the data file with stringsAsFactors = FALSE, like this you 
don't have character vectors, you have factors, which are coded as 
consecutive integers 1, 2, etc.


?read.table
?read.csv

See in particular the argument above, stringsAsFactors

Hope this helps,

Rui Barradas

Em 01-08-2012 15:21, algotr8der escreveu:

I have an object, which I pull in from a csv file here
http://r.789695.n4.nabble.com/file/n4638691/jan_2011.csv jan_2011.csv

mydata <- read.csv("jan_2011.csv", header=TRUE, sep=",")


head(mydata)

   Delivery.Date Hour.Ending Repeated.Hour.Flag Settlement.Point
Settlement.Point.Price
101/01/2011   01:00  NHB_BUSAVG
25.18
201/01/2011   01:00  N   HB_HOUSTON
25.36
301/01/2011   01:00  NHB_HUBAVG
25.07
401/01/2011   01:00  N HB_NORTH
25.33
501/01/2011   01:00  N HB_SOUTH
25.12
601/01/2011   01:00  N  HB_WEST
24.49


str(mydata)

'data.frame':   10416 obs. of  5 variables:
  $ Delivery.Date : Factor w/ 31 levels "01/01/2011","01/02/2011",..:
1 1 1 1 1 1 1 1 1 1 ...
  $ Hour.Ending   : Factor w/ 24 levels "01:00","02:00",..: 1 1 1 1 1
1 1 1 1 1 ...
  $ Repeated.Hour.Flag: Factor w/ 1 level "N": 1 1 1 1 1 1 1 1 1 1 ...
  $ Settlement.Point  : Factor w/ 14 levels "HB_BUSAVG","HB_HOUSTON",..:
1 2 3 4 5 6 7 8 9 10 ...
  $ Settlement.Point.Price: num  25.2 25.4 25.1 25.3 25.1 ...

I want to convert the Delivery.Date field to a date object. I tried various
attempts but failed with the following:


as.Date(mydata[1], "%m/%d/%Y")

Error in as.Date.default(ercot[1], "%m/%d/%Y") :
   do not know how to convert 'ercot[1]' to class "Date"

I even tried to save the first column to a separate object and tried the
same but got the same result.  At this point I'm not sure how to move
forward. Appreciate the help.





--
View this message in context: 
http://r.789695.n4.nabble.com/as-date-do-not-know-how-to-convert-test-1-to-class-Date-tp4638691.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


__
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] as.date: do not know how to convert 'test[1]' to class "Date"

2012-08-01 Thread R. Michael Weylandt
Please don't post files to nabble in the future -- when Nabble removes
them, we then have a broken link in the real archives: dput() is much
preferred way to send data.

Anyways:

# mydata <- read.csv("http://r.789695.n4.nabble.com/file/n4638691/jan_2011.csv";)
#
# dput(head(mydata, 15))

structure(list(Delivery.Date = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("01/01/2011",
"01/02/2011", "01/03/2011", "01/04/2011", "01/05/2011", "01/06/2011",
"01/07/2011", "01/08/2011", "01/09/2011", "01/10/2011", "01/11/2011",
"01/12/2011", "01/13/2011", "01/14/2011", "01/15/2011", "01/16/2011",
"01/17/2011", "01/18/2011", "01/19/2011", "01/20/2011", "01/21/2011",
"01/22/2011", "01/23/2011", "01/24/2011", "01/25/2011", "01/26/2011",
"01/27/2011", "01/28/2011", "01/29/2011", "01/30/2011", "01/31/2011"
), class = "factor"), Hour.Ending = structure(c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("01:00",
"02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00",
"09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00",
"16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00",
"23:00", "24:00"), class = "factor"), Repeated.Hour.Flag = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "N",
class = "factor"),
Settlement.Point = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 1L), .Label = c("HB_BUSAVG",
"HB_HOUSTON", "HB_HUBAVG", "HB_NORTH", "HB_SOUTH", "HB_WEST",
"LZ_AEN", "LZ_CPS", "LZ_HOUSTON", "LZ_LCRA", "LZ_NORTH",
"LZ_RAYBN", "LZ_SOUTH", "LZ_WEST"), class = "factor"),
Settlement.Point.Price = c(25.18,
25.36, 25.07, 25.33, 25.12, 24.49, 25.2, 25.12, 25.41, 25.15,
25.32, 25.32, 25.1, 25.07, 23.84)), .Names = c("Delivery.Date",
"Hour.Ending", "Repeated.Hour.Flag", "Settlement.Point",
"Settlement.Point.Price"
), row.names = c(NA, 15L), class = "data.frame")

mydata[,1] <- as.Date(mydata[,1], format = "%m/%d/%Y")

works just fine for me. Note that you were missing a column.

On Wed, Aug 1, 2012 at 9:21 AM, algotr8der  wrote:
> I have an object, which I pull in from a csv file here
> http://r.789695.n4.nabble.com/file/n4638691/jan_2011.csv jan_2011.csv
>
> mydata <- read.csv("jan_2011.csv", header=TRUE, sep=",")
>
>> head(mydata)
>   Delivery.Date Hour.Ending Repeated.Hour.Flag Settlement.Point
> Settlement.Point.Price
> 101/01/2011   01:00  NHB_BUSAVG
> 25.18
> 201/01/2011   01:00  N   HB_HOUSTON
> 25.36
> 301/01/2011   01:00  NHB_HUBAVG
> 25.07
> 401/01/2011   01:00  N HB_NORTH
> 25.33
> 501/01/2011   01:00  N HB_SOUTH
> 25.12
> 601/01/2011   01:00  N  HB_WEST
> 24.49
>
>> str(mydata)
> 'data.frame':   10416 obs. of  5 variables:
>  $ Delivery.Date : Factor w/ 31 levels "01/01/2011","01/02/2011",..:
> 1 1 1 1 1 1 1 1 1 1 ...
>  $ Hour.Ending   : Factor w/ 24 levels "01:00","02:00",..: 1 1 1 1 1
> 1 1 1 1 1 ...
>  $ Repeated.Hour.Flag: Factor w/ 1 level "N": 1 1 1 1 1 1 1 1 1 1 ...
>  $ Settlement.Point  : Factor w/ 14 levels "HB_BUSAVG","HB_HOUSTON",..:
> 1 2 3 4 5 6 7 8 9 10 ...
>  $ Settlement.Point.Price: num  25.2 25.4 25.1 25.3 25.1 ...
>
> I want to convert the Delivery.Date field to a date object. I tried various
> attempts but failed with the following:
>
>> as.Date(mydata[1], "%m/%d/%Y")
> Error in as.Date.default(ercot[1], "%m/%d/%Y") :
>   do not know how to convert 'ercot[1]' to class "Date"

No idea where this "ercot" thing comes from.

Best,
Michael

>
> I even tried to save the first column to a separate object and tried the
> same but got the same result.  At this point I'm not sure how to move
> forward. Appreciate the help.
>
>
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/as-date-do-not-know-how-to-convert-test-1-to-class-Date-tp4638691.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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.

__
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] as.date: do not know how to convert 'mydata[1]' to class "Date"

2012-08-01 Thread algotr8der
Thank you Ricardogg and Arun. I don't know how I missed that. Too many
sleepless nights perhaps. Thank you. 



--
View this message in context: 
http://r.789695.n4.nabble.com/as-date-do-not-know-how-to-convert-mydata-1-to-class-Date-tp4638691p4638708.html
Sent from the R help mailing list archive at Nabble.com.

__
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] as.date: do not know how to convert 'mydata[1]' to class "Date"

2012-08-01 Thread Ricardogg
For me it owrks when i write it like:

as.Date(paste(mydata$Delivery.Date), "%m/%d/%Y") 

Hope it works,

Regards,

Ricardo



--
View this message in context: 
http://r.789695.n4.nabble.com/as-date-do-not-know-how-to-convert-mydata-1-to-class-Date-tp4638691p4638696.html
Sent from the R help mailing list archive at Nabble.com.

__
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] as.Date error

2011-04-18 Thread David Winsemius


On Apr 17, 2011, at 7:24 PM, Wonjae Lee wrote:



Thank you for replying the as.Date error question.

I have one more question as below.
I used cbind command, and data x changed, 2010-11-16 to 14929,  
2010-11-17 to

14930.
What happened to them?
What should I do to see -mm-dd format data?


x=c("11/16/2010","11/17/2010","11/18/2010","11/19/2010")
x=as.Date(x,"%m/%d/%Y")
x

[1] "2010-11-16" "2010-11-17" "2010-11-18" "2010-11-19"

y=c(1753.75,15077,1759.35,15078)
cbind(x,y)

xy
[1,] 14929  1753.75
[2,] 14930 15077.00
[3,] 14931  1759.35
[4,] 14932 15078.00



cbind.default will return a matrix which needs to have all of its  
elements of the same type, so your dates were coerced to numeric since  
their internal representation is as integers.


Had you created x as a data.frame, then cbind would have called  
cbind.data.frame which was probably what you wanted to happen.


> xdat <-data.frame(x=as.Date(x,"%m/%d/%Y"))
> cbind(xdat,y)
   xy
1 2010-11-16  1753.75
2 2010-11-17 15077.00
3 2010-11-18  1759.35
4 2010-11-19 15078.00

--

David Winsemius, MD
West Hartford, CT

__
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] as.Date function error

2011-04-17 Thread Achim Zeileis

On Sun, 17 Apr 2011, Wonjae Lee wrote:


Hi,

I have some problems with as.Date function.
After I applied as.Date for my data, "2010" changed to "2020" as below
Where am I wrong?


You used %y (two-digit year, here: "20" and then expanded to "2020") 
instead of %Y (four-digit year, here "2010").


Using as.Date(x,"%m/%d/%Y") yields the desired result.
Z




Thanks

Wonjae


x=c("11/16/2010","11/17/2010","11/18/2010","11/19/2010")
x=as.Date(x,"%m/%d/%y")
x

[1] "2020-11-16" "2020-11-17" "2020-11-18" "2020-11-19"

my R veision is 2.12.2.

--
View this message in context: 
http://r.789695.n4.nabble.com/as-Date-function-error-tp3455466p3455466.html
Sent from the R help mailing list archive at Nabble.com.

__
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.



__
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] as.Date function error

2011-04-17 Thread Dennis Murphy
as.Date(x,"%m/%d/%Y")
[1] "2010-11-16" "2010-11-17" "2010-11-18" "2010-11-19"

Notice the Y (four digit date).

Dennis

On Sun, Apr 17, 2011 at 6:34 AM, Wonjae Lee  wrote:
> Hi,
>
> I have some problems with as.Date function.
> After I applied as.Date for my data, "2010" changed to "2020" as below
> Where am I wrong?
>
> Thanks
>
> Wonjae
>
>> x=c("11/16/2010","11/17/2010","11/18/2010","11/19/2010")
>> x=as.Date(x,"%m/%d/%y")
>> x
> [1] "2020-11-16" "2020-11-17" "2020-11-18" "2020-11-19"
>
> my R veision is 2.12.2.
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/as-Date-function-error-tp3455466p3455466.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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.
>

__
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] as.Date

2011-02-09 Thread BXC (Bendix Carstensen)
We spotted that there were problems, and have realized that the as.Date.numeric 
was a left-over form earlier; it will be removed in the next version of the Epi 
package.
Thanks for the help.
br.
Bendix 

> -Original Message-
> From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] 
> Sent: 9. februar 2011 11:48
> To: Philipp Pagel
> Cc: BXC (Bendix Carstensen); r-help@r-project.org
> Subject: Re: [R] as.Date
> 
> And I am hereby reporting this bug to the package maintainer.
> 
> On Wed, 9 Feb 2011, Philipp Pagel wrote:
> 
> > On Wed, Feb 09, 2011 at 08:44:30AM +0100, Valeri Fabio wrote:
> >> Hello,
> >>
> >> I find out which package disturbs as.Date(). It is the package Epi:
> >>
> >>> as.Date(36525, origin="1900-01-01")
> >> [1] "2000-01-02"
> >>> library(Epi)
> >>> as.Date(36525, origin="1900-01-01")
> >> [1] "2070-01-01"
> >>> detach("package:Epi")
> >>> as.Date(36525, origin="1900-01-01")
> >> [1] "2000-01-02"
> >
> > OK - that makes sense. Epi has its own as.Date.numeric function and 
> > upon loading the package you get a warning:
> >
> >
> >> library(Epi)
> > Attaching package: 'Epi'
> > The following object(s) are masked from 'package:base':
> >as.Date.numeric, merge.data.frame
> >
> >
> > A quick look at the manual page confirms that Epi's version 
> does not 
> > have an origin option.
> >
> > cu
> > Philipp
> >
> > --
> > Dr. Philipp Pagel
> > Lehrstuhl für Genomorientierte Bioinformatik Technische Universität 
> > München Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3
> > 85354 Freising, Germany
> > http://webclu.bio.wzw.tum.de/~pagel/
> >
> > __
> > 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.
> >
> 
> -- 
> Brian D. Ripley,  rip...@stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
__
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] as.Date

2011-02-09 Thread Prof Brian Ripley

And I am hereby reporting this bug to the package maintainer.

On Wed, 9 Feb 2011, Philipp Pagel wrote:


On Wed, Feb 09, 2011 at 08:44:30AM +0100, Valeri Fabio wrote:

Hello,

I find out which package disturbs as.Date(). It is the package Epi:


as.Date(36525, origin="1900-01-01")

[1] "2000-01-02"

library(Epi)
as.Date(36525, origin="1900-01-01")

[1] "2070-01-01"

detach("package:Epi")
as.Date(36525, origin="1900-01-01")

[1] "2000-01-02"


OK - that makes sense. Epi has its own as.Date.numeric function and
upon loading the package you get a warning:



library(Epi)

Attaching package: 'Epi'
The following object(s) are masked from 'package:base':
   as.Date.numeric, merge.data.frame


A quick look at the manual page confirms that Epi's version does not
have an origin option.

cu
Philipp

--
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/

__
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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
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] as.Date

2011-02-09 Thread Philipp Pagel
On Wed, Feb 09, 2011 at 08:44:30AM +0100, Valeri Fabio wrote:
> Hello,
> 
> I find out which package disturbs as.Date(). It is the package Epi:
> 
> > as.Date(36525, origin="1900-01-01")
> [1] "2000-01-02"
> > library(Epi)
> > as.Date(36525, origin="1900-01-01")
> [1] "2070-01-01"
> > detach("package:Epi")
> > as.Date(36525, origin="1900-01-01")
> [1] "2000-01-02"

OK - that makes sense. Epi has its own as.Date.numeric function and
upon loading the package you get a warning:


> library(Epi)
Attaching package: 'Epi'
The following object(s) are masked from 'package:base':
as.Date.numeric, merge.data.frame


A quick look at the manual page confirms that Epi's version does not
have an origin option. 

cu
Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/

__
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] as.Date

2011-02-09 Thread Valeri Fabio
Hello,

I find out which package disturbs as.Date(). It is the package Epi:

> as.Date(36525, origin="1900-01-01")
[1] "2000-01-02"
> library(Epi)
> as.Date(36525, origin="1900-01-01")
[1] "2070-01-01"
> detach("package:Epi")
> as.Date(36525, origin="1900-01-01")
[1] "2000-01-02"

@Philipp: I assume that Epi will have the same affect on Linux. Maybe you have 
the same library or another which conflicts with as.Date(). 

Fabio



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Valeri Fabio
Sent: Mittwoch, 9. Februar 2011 08:12
To: r-help@r-project.org
Subject: Re: [R] as.Date

Thanks for the reply.

The original test was without the quote. The quote come into play when I try to 
solve this problem changing from " to '. However, after restarting my PC the 

as.Date(36525, origin="1900-01-01")

gaves me the correct output
[1] "2000-01-02"

After loading several libraries I got
[1] "2070-01-01"

I assume there is a conflict with a package. I will try to find the one and let 
you know.

Fabio


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Prof Brian Ripley
Sent: Dienstag, 8. Februar 2011 18:45
To: Philipp Pagel
Cc: r-help@r-project.org
Subject: Re: [R] as.Date

On Tue, 8 Feb 2011, Philipp Pagel wrote:

>> I have a strange behavior of the as.Date() function. For example:
>> as.Date(36525, origin="1900-01-01'")
>>
>> I would expect to get 2000-01-01. But R gives me
>
> That's almost exactly what I get with R 2.11.1, LINUX (minus the 
> one-day differnce which is probably correct, too lazy to count leap
> years...):
>
>> as.Date(36525, origin="1900-01-01'")
> [1] "2000-01-02"
>
> At first I thought the excess single quote maight be causingyour 
> problem, but it doesn't for me.
>
> Maybe you need to upgrade R? Possibly it's an already fixed issue?

Or perhaps it is a problem with the OS services on the unstated R platform used 
(this will use strptime from the OS).  The single quote is definitely wrong, 
however.

>
> cu
>   Philipp
>
>
> -- 
> Dr. Philipp Pagel
> Lehrstuhl für Genomorientierte Bioinformatik
> Technische Universität München
> Wissenschaftszentrum Weihenstephan
> Maximus-von-Imhof-Forum 3
> 85354 Freising, Germany
> http://webclu.bio.wzw.tum.de/~pagel/
>
> __
> 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.
>

-- 
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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.

__
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] as.Date

2011-02-08 Thread Valeri Fabio
Thanks for the reply.

The original test was without the quote. The quote come into play when I try to 
solve this problem changing from " to '. However, after restarting my PC the 

as.Date(36525, origin="1900-01-01")

gaves me the correct output
[1] "2000-01-02"

After loading several libraries I got
[1] "2070-01-01"

I assume there is a conflict with a package. I will try to find the one and let 
you know.

Fabio


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Prof Brian Ripley
Sent: Dienstag, 8. Februar 2011 18:45
To: Philipp Pagel
Cc: r-help@r-project.org
Subject: Re: [R] as.Date

On Tue, 8 Feb 2011, Philipp Pagel wrote:

>> I have a strange behavior of the as.Date() function. For example:
>> as.Date(36525, origin="1900-01-01'")
>>
>> I would expect to get 2000-01-01. But R gives me
>
> That's almost exactly what I get with R 2.11.1, LINUX (minus the 
> one-day differnce which is probably correct, too lazy to count leap
> years...):
>
>> as.Date(36525, origin="1900-01-01'")
> [1] "2000-01-02"
>
> At first I thought the excess single quote maight be causingyour 
> problem, but it doesn't for me.
>
> Maybe you need to upgrade R? Possibly it's an already fixed issue?

Or perhaps it is a problem with the OS services on the unstated R platform used 
(this will use strptime from the OS).  The single quote is definitely wrong, 
however.

>
> cu
>   Philipp
>
>
> -- 
> Dr. Philipp Pagel
> Lehrstuhl für Genomorientierte Bioinformatik
> Technische Universität München
> Wissenschaftszentrum Weihenstephan
> Maximus-von-Imhof-Forum 3
> 85354 Freising, Germany
> http://webclu.bio.wzw.tum.de/~pagel/
>
> __
> 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.
>

-- 
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] as.Date

2011-02-08 Thread Prof Brian Ripley

On Tue, 8 Feb 2011, Philipp Pagel wrote:


I have a strange behavior of the as.Date() function. For example:
as.Date(36525, origin="1900-01-01'")

I would expect to get 2000-01-01. But R gives me


That's almost exactly what I get with R 2.11.1, LINUX (minus the
one-day differnce which is probably correct, too lazy to count leap
years...):


as.Date(36525, origin="1900-01-01'")

[1] "2000-01-02"

At first I thought the excess single quote maight be causingyour
problem, but it doesn't for me.

Maybe you need to upgrade R? Possibly it's an already fixed issue?


Or perhaps it is a problem with the OS services on the unstated R 
platform used (this will use strptime from the OS).  The single quote 
is definitely wrong, however.




cu
Philipp


--
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/

__
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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
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] as.Date

2011-02-08 Thread Philipp Pagel
> I have a strange behavior of the as.Date() function. For example:
> as.Date(36525, origin="1900-01-01'")
> 
> I would expect to get 2000-01-01. But R gives me

That's almost exactly what I get with R 2.11.1, LINUX (minus the
one-day differnce which is probably correct, too lazy to count leap
years...):

> as.Date(36525, origin="1900-01-01'")
[1] "2000-01-02"

At first I thought the excess single quote maight be causingyour
problem, but it doesn't for me.

Maybe you need to upgrade R? Possibly it's an already fixed issue?

cu
Philipp


-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/

__
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] as.Date

2011-02-08 Thread David Winsemius


On Feb 8, 2011, at 11:15 AM, Valeri Fabio wrote:


Hi everybody,



I have a strange behavior of the as.Date() function.


No, you have a programming error.


For example:



as.Date(36525, origin="1900-01-01'")


You have a superfluous "'"

> as.Date(36525, origin="1900-01-01")
[1] "2000-01-02"





I would expect to get 2000-01-01. But R gives me



[1] "2070-01-01"



I tried with several origins but the results are still the same. It
seems that the origin does not apply and remains 1970-01-01.



Does anyone can give me a hint  how to solve this problem?



Thanks very much.



Fabio












---

Fabio Valeri, MSc

University of Bern

Institute of Social and Preventive Medicine

Division of International & Environmental Health

Finkenhubelweg 11 - CH-3012 Bern

Tel +41 (0)31 631 35 10 - Fax +41 (0)31 631 35 20 - www.ispm.ch




[[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.


David Winsemius, MD
West Hartford, CT

__
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] as.Date() add a day to a date

2010-09-13 Thread David Winsemius


Try this:

format(dt, '%Y-%m-%d'), if you want Date class:

as.Date(format(dt, '%Y-%m-%d'))



On Mon, Sep 13, 2010 at 2:24 PM, Andrew Yee   
wrote:
Thanks David, now I wonder how you can have as.Date() render the  
date using

local time rather than UTC.

Andrew

On Mon, Sep 13, 2010 at 12:08 PM, David Winsemius >wrote:


>
> On Sep 13, 2010, at 11:56 AM, Andrew Yee wrote:
>
>  I'm trying to understand why as.Date() is converting a the  
modified date

>> of
>> a file from August 22 to August 23.
>>
>>  foo <- file.info(file.to.process)
>>> str(foo)
>>>
>> 'data.frame':   1 obs. of  10 variables:
>> $ size  : num 5.37e+09
>> $ isdir : logi FALSE
>> $ mode  :Class 'octmode'  int 436
>> $ mtime : POSIXct, format: "2010-08-22 23:14:52"
>> $ ctime : POSIXct, format: "2010-09-13 11:34:31"
>> $ atime : POSIXct, format: "2010-09-09 15:42:00"
>> $ uid   : int 503
>> $ gid   : int 503
>> $ uname : chr "ayee"
>> $ grname: chr "ayee"
>>
>>  as.Date(foo$mtime)
>>>
>> [1] "2010-08-23"
>>
>> In this case as.Date(foo$mtime) gives August 23.  I would have  
expected

>> August 22.
>>
>
> You are pretty close to midnight. Probably a TZ issue. Check your  
locale

> settings versus UTC/GMT.
>
> >  dt <- as.POSIXct("2010-08-22 23:14:52")
> > as.Date(dt)
> [1] "2010-08-23"
>
> Happens to me too, but when its 23:14 here, (US-EDT) it's the next  
day in

> Greenwich. The help page says:
> "The last [POSIXct] is converted to days by ignoring the time after
> midnight in the representation of the time in UTC." That is not  
entirely
> clear to my reading, but I am forced to conclude that it means  
as.Date

> returns the Date in UTC terms rather than in local terms.
>
> --
> David.
>
>
>> Thanks,
>> Andrew
>>
>>  sessionInfo()
>>>
>> R version 2.11.1 Patched (2010-09-11 r52901)
>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>
>> locale:
>> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>> [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
>> [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>> [9] LC_ADDRESS=C   LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods
base

>>
>>[[alternative HTML version deleted]]
>>


--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

__
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] as.Date() add a day to a date

2010-09-13 Thread Andrew Yee
Henrique, thanks for your suggestion.  For my applications, character would
have been sufficient, so your suggestion of using format() works fine too.

Perhaps I should submit a feature request for as.Date() to let you specify
local time.

Thanks,
Andrew

On Mon, Sep 13, 2010 at 2:06 PM, Henrique Dallazuanna wrote:

> Try this:
>
> format(dt, '%Y-%m-%d'), if you want Date class:
>
> as.Date(format(dt, '%Y-%m-%d'))
>
>
>
>
> On Mon, Sep 13, 2010 at 2:24 PM, Andrew Yee  wrote:
>
>> Thanks David, now I wonder how you can have as.Date() render the date
>> using
>> local time rather than UTC.
>>
>> Andrew
>>
>> On Mon, Sep 13, 2010 at 12:08 PM, David Winsemius > >wrote:
>>
>> >
>> > On Sep 13, 2010, at 11:56 AM, Andrew Yee wrote:
>> >
>> >  I'm trying to understand why as.Date() is converting a the modified
>> date
>> >> of
>> >> a file from August 22 to August 23.
>> >>
>> >>  foo <- file.info(file.to.process)
>> >>> str(foo)
>> >>>
>> >> 'data.frame':   1 obs. of  10 variables:
>> >> $ size  : num 5.37e+09
>> >> $ isdir : logi FALSE
>> >> $ mode  :Class 'octmode'  int 436
>> >> $ mtime : POSIXct, format: "2010-08-22 23:14:52"
>> >> $ ctime : POSIXct, format: "2010-09-13 11:34:31"
>> >> $ atime : POSIXct, format: "2010-09-09 15:42:00"
>> >> $ uid   : int 503
>> >> $ gid   : int 503
>> >> $ uname : chr "ayee"
>> >> $ grname: chr "ayee"
>> >>
>> >>  as.Date(foo$mtime)
>> >>>
>> >> [1] "2010-08-23"
>> >>
>> >> In this case as.Date(foo$mtime) gives August 23.  I would have expected
>> >> August 22.
>> >>
>> >
>> > You are pretty close to midnight. Probably a TZ issue. Check your locale
>> > settings versus UTC/GMT.
>> >
>> > >  dt <- as.POSIXct("2010-08-22 23:14:52")
>> > > as.Date(dt)
>> > [1] "2010-08-23"
>> >
>> > Happens to me too, but when its 23:14 here, (US-EDT) it's the next day
>> in
>> > Greenwich. The help page says:
>> > "The last [POSIXct] is converted to days by ignoring the time after
>> > midnight in the representation of the time in UTC." That is not entirely
>> > clear to my reading, but I am forced to conclude that it means as.Date
>> > returns the Date in UTC terms rather than in local terms.
>> >
>> > --
>> > David.
>> >
>> >
>> >> Thanks,
>> >> Andrew
>> >>
>> >>  sessionInfo()
>> >>>
>> >> R version 2.11.1 Patched (2010-09-11 r52901)
>> >> Platform: x86_64-unknown-linux-gnu (64-bit)
>> >>
>> >> locale:
>> >> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>> >> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>> >> [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
>> >> [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>> >> [9] LC_ADDRESS=C   LC_TELEPHONE=C
>> >> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>> >>
>> >> attached base packages:
>> >> [1] stats graphics  grDevices utils datasets  methods   base
>> >>
>> >>[[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.
>> >>
>> >
>> > David Winsemius, MD
>> > West Hartford, CT
>> >
>> >
>>
>>[[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.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

[[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] as.Date() add a day to a date

2010-09-13 Thread David Winsemius

On Sep 13, 2010, at 1:24 PM, Andrew Yee wrote:

> Thanks David, now I wonder how you can have as.Date() render the  
> date using local time rather than UTC.
>

Since we are both in the EDT TZ at the moment,  our times are UTC-4  
(hours = 60*60 seconds)

 > dt <- as.POSIXct("2010-08-22 23:14:52")
 >  as.Date(dt -60*60*4)
Now   == [1] "2010-08-22"
 > #was [1] "2010-08-23"

There are probably more elegant and self-documenting methods, but I'm  
not fully versed in TZ conumdrums.

-- 
David.

> Andrew
>
> On Mon, Sep 13, 2010 at 12:08 PM, David Winsemius  > wrote:
>
> On Sep 13, 2010, at 11:56 AM, Andrew Yee wrote:
>
> I'm trying to understand why as.Date() is converting a the modified  
> date of
> a file from August 22 to August 23.
>
> foo <- file.info(file.to.process)
> str(foo)
> 'data.frame':   1 obs. of  10 variables:
> $ size  : num 5.37e+09
> $ isdir : logi FALSE
> $ mode  :Class 'octmode'  int 436
> $ mtime : POSIXct, format: "2010-08-22 23:14:52"
> $ ctime : POSIXct, format: "2010-09-13 11:34:31"
> $ atime : POSIXct, format: "2010-09-09 15:42:00"
> $ uid   : int 503
> $ gid   : int 503
> $ uname : chr "ayee"
> $ grname: chr "ayee"
>
> as.Date(foo$mtime)
> [1] "2010-08-23"
>
> In this case as.Date(foo$mtime) gives August 23.  I would have  
> expected
> August 22.
>
> You are pretty close to midnight. Probably a TZ issue. Check your  
> locale settings versus UTC/GMT.
>
> >  dt <- as.POSIXct("2010-08-22 23:14:52")
> > as.Date(dt)
> [1] "2010-08-23"
>
> Happens to me too, but when its 23:14 here, (US-EDT) it's the next  
> day in Greenwich. The help page says:
> "The last [POSIXct] is converted to days by ignoring the time after  
> midnight in the representation of the time in UTC." That is not  
> entirely clear to my reading, but I am forced to conclude that it  
> means as.Date returns the Date in UTC terms rather than in local  
> terms.
>
> -- 
> David.
>
>
> Thanks,
> Andrew
>
> sessionInfo()
> R version 2.11.1 Patched (2010-09-11 r52901)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
> [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
>[[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.
>
> David Winsemius, MD
> West Hartford, CT
>
>

David Winsemius, MD
West Hartford, CT


[[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] as.Date() add a day to a date

2010-09-13 Thread Andrew Yee
Thanks David, now I wonder how you can have as.Date() render the date using
local time rather than UTC.

Andrew

On Mon, Sep 13, 2010 at 12:08 PM, David Winsemius wrote:

>
> On Sep 13, 2010, at 11:56 AM, Andrew Yee wrote:
>
>  I'm trying to understand why as.Date() is converting a the modified date
>> of
>> a file from August 22 to August 23.
>>
>>  foo <- file.info(file.to.process)
>>> str(foo)
>>>
>> 'data.frame':   1 obs. of  10 variables:
>> $ size  : num 5.37e+09
>> $ isdir : logi FALSE
>> $ mode  :Class 'octmode'  int 436
>> $ mtime : POSIXct, format: "2010-08-22 23:14:52"
>> $ ctime : POSIXct, format: "2010-09-13 11:34:31"
>> $ atime : POSIXct, format: "2010-09-09 15:42:00"
>> $ uid   : int 503
>> $ gid   : int 503
>> $ uname : chr "ayee"
>> $ grname: chr "ayee"
>>
>>  as.Date(foo$mtime)
>>>
>> [1] "2010-08-23"
>>
>> In this case as.Date(foo$mtime) gives August 23.  I would have expected
>> August 22.
>>
>
> You are pretty close to midnight. Probably a TZ issue. Check your locale
> settings versus UTC/GMT.
>
> >  dt <- as.POSIXct("2010-08-22 23:14:52")
> > as.Date(dt)
> [1] "2010-08-23"
>
> Happens to me too, but when its 23:14 here, (US-EDT) it's the next day in
> Greenwich. The help page says:
> "The last [POSIXct] is converted to days by ignoring the time after
> midnight in the representation of the time in UTC." That is not entirely
> clear to my reading, but I am forced to conclude that it means as.Date
> returns the Date in UTC terms rather than in local terms.
>
> --
> David.
>
>
>> Thanks,
>> Andrew
>>
>>  sessionInfo()
>>>
>> R version 2.11.1 Patched (2010-09-11 r52901)
>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>
>> locale:
>> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>> [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
>> [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>> [9] LC_ADDRESS=C   LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>>
>>[[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.
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

[[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] as.Date() add a day to a date

2010-09-13 Thread David Winsemius


On Sep 13, 2010, at 11:56 AM, Andrew Yee wrote:

I'm trying to understand why as.Date() is converting a the modified  
date of

a file from August 22 to August 23.


foo <- file.info(file.to.process)
str(foo)

'data.frame':   1 obs. of  10 variables:
$ size  : num 5.37e+09
$ isdir : logi FALSE
$ mode  :Class 'octmode'  int 436
$ mtime : POSIXct, format: "2010-08-22 23:14:52"
$ ctime : POSIXct, format: "2010-09-13 11:34:31"
$ atime : POSIXct, format: "2010-09-09 15:42:00"
$ uid   : int 503
$ gid   : int 503
$ uname : chr "ayee"
$ grname: chr "ayee"


as.Date(foo$mtime)

[1] "2010-08-23"

In this case as.Date(foo$mtime) gives August 23.  I would have  
expected

August 22.


You are pretty close to midnight. Probably a TZ issue. Check your  
locale settings versus UTC/GMT.


>  dt <- as.POSIXct("2010-08-22 23:14:52")
> as.Date(dt)
[1] "2010-08-23"

Happens to me too, but when its 23:14 here, (US-EDT) it's the next day  
in Greenwich. The help page says:
"The last [POSIXct] is converted to days by ignoring the time after  
midnight in the representation of the time in UTC." That is not  
entirely clear to my reading, but I am forced to conclude that it  
means as.Date returns the Date in UTC terms rather than in local terms.


--
David.



Thanks,
Andrew


sessionInfo()

R version 2.11.1 Patched (2010-09-11 r52901)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8   LC_NAME=C
[9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

[[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.


David Winsemius, MD
West Hartford, CT

__
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] as.date

2010-06-01 Thread arnaud Gaboury
TY for the tip. The lower case is in fact the culprit.





> -Original Message-
> From: Erik Iverson [mailto:er...@ccbr.umn.edu]
> Sent: Tuesday, June 01, 2010 6:05 PM
> To: arnaud Gaboury
> Cc: r-help@r-project.org
> Subject: Re: [R] as.date
> 
> 
> > Where does the problem comes from?? Maybe from my sytem date ??
> 
> Simply from not reading the options carefully enough, from ?strptime,
> 
>   '%y' Year without century (00-99). If you use this on input,
> which
>century you get is system-specific.  So don't!  Most often
>values 00 to 68 are prefixed by 20 and 69 to 99 by 19 - that
>is the behaviour specified by the 2001 POSIX standard, but
> it
>does also say 'it is expected that in a future version of
>IEEE Std 1003.1-2001 the default century inferred from a
>2-digit year will change'.
> 
>   '%Y' Year with century.
> 
> 
> You want %Y, not %y.

__
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] as.date

2010-06-01 Thread Joris Meys
Change this line to :

>pose$CREATED.DATE=as.Date(pose$CREATED.DATE,"%d/%m/%Y") # mind the capital
Y
>pose
  DESCRIPTION CREATED.DATE QUANITY CLOSING.PRICE
1 COTTON NO.2 Jul/10   2010-05-13   1   81.2000
2 COTTON NO.2 Jul/10   2010-05-13   1   81.2000
3   PALLADIUM Jun/10   2010-05-14  -1  503.6000
4   PALLADIUM Jun/10   2010-05-14  -1  503.6000
5 SUGAR NO.11 Jul/10   2010-05-10   1   13.8900
6 SUGAR NO.11 Jul/10   2010-05-10   1   13.8900

Cheers
Joris

On Tue, Jun 1, 2010 at 5:57 PM, arnaud Gaboury wrote:

> Dear group,
>
> Here is my df (obtained with a read.csv2()):
>
>
> df <-
> structure(list(DESCRIPTION = c("COTTON NO.2 Jul/10", "COTTON NO.2 Jul/10",
> "PALLADIUM Jun/10", "PALLADIUM Jun/10", "SUGAR NO.11 Jul/10",
> "SUGAR NO.11 Jul/10"), CREATED.DATE = c("13/05/2010", "13/05/2010",
> "14/05/2010", "14/05/2010", "10/05/2010", "10/05/2010"), QUANITY = c(1,
> 1, -1, -1, 1, 1), CLOSING.PRICE = c("81.2000", "81.2000", "503.6000",
> "503.6000", "13.8900", "13.8900")), .Names = c("DESCRIPTION",
> "CREATED.DATE", "QUANITY", "CLOSING.PRICE"), row.names = c(NA,
> 6L), class = "data.frame")
>
> > str(df)
> 'data.frame':   6 obs. of  4 variables:
>  $ DESCRIPTION  : chr  "COTTON NO.2 Jul/10" "COTTON NO.2 Jul/10" "PALLADIUM
> Jun/10" "PALLADIUM Jun/10" ...
>  $ CREATED.DATE : chr  "13/05/2010" "13/05/2010" "14/05/2010" "14/05/2010"
> ...
>  $ QUANITY  : num  1 1 -1 -1 1 1
>  $ CLOSING.PRICE: chr  "81.2000" "81.2000" "503.6000" "503.6000" ...
>
> I want to change the class of df$CREATED.DATE from Chr to Date:
>
>
> >pose$CREATED.DATE=as.Date(pose$CREATED.DATE,"%d/%m/%y")
>
> Here is what I get :
>
> df <-
> structure(list(DESCRIPTION = c("COTTON NO.2 Jul/10", "COTTON NO.2 Jul/10",
> "PALLADIUM Jun/10", "PALLADIUM Jun/10", "SUGAR NO.11 Jul/10",
> "SUGAR NO.11 Jul/10"), CREATED.DATE = structure(c(18395, 18395,
> 18396, 18396, 18392, 18392), class = "Date"), QUANITY = c(1,
> 1, -1, -1, 1, 1), CLOSING.PRICE = c("81.2000", "81.2000", "503.6000",
> "503.6000", "13.8900", "13.8900")), .Names = c("DESCRIPTION",
> "CREATED.DATE", "QUANITY", "CLOSING.PRICE"), row.names = c(NA,
> 6L), class = "data.frame")
>
> Where does the problem comes from?? Maybe from my sytem date ??
>
> TY for any help
>
> __
> 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.
>



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

[[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] as.date

2010-06-01 Thread Joshua Wiley
Hello,

The lowercase 'y' is year without century.  This should work for you:

as.Date(x=df$CREATED.DATE, format="%d/%m/%Y")

HTH,

Josh


On Tue, Jun 1, 2010 at 8:57 AM, arnaud Gaboury  wrote:
> Dear group,
>
> Here is my df (obtained with a read.csv2()):
>
>
> df <-
> structure(list(DESCRIPTION = c("COTTON NO.2 Jul/10", "COTTON NO.2 Jul/10",
> "PALLADIUM Jun/10", "PALLADIUM Jun/10", "SUGAR NO.11 Jul/10",
> "SUGAR NO.11 Jul/10"), CREATED.DATE = c("13/05/2010", "13/05/2010",
> "14/05/2010", "14/05/2010", "10/05/2010", "10/05/2010"), QUANITY = c(1,
> 1, -1, -1, 1, 1), CLOSING.PRICE = c("81.2000", "81.2000", "503.6000",
> "503.6000", "13.8900", "13.8900")), .Names = c("DESCRIPTION",
> "CREATED.DATE", "QUANITY", "CLOSING.PRICE"), row.names = c(NA,
> 6L), class = "data.frame")
>
>> str(df)
> 'data.frame':   6 obs. of  4 variables:
>  $ DESCRIPTION  : chr  "COTTON NO.2 Jul/10" "COTTON NO.2 Jul/10" "PALLADIUM
> Jun/10" "PALLADIUM Jun/10" ...
>  $ CREATED.DATE : chr  "13/05/2010" "13/05/2010" "14/05/2010" "14/05/2010"
> ...
>  $ QUANITY      : num  1 1 -1 -1 1 1
>  $ CLOSING.PRICE: chr  "81.2000" "81.2000" "503.6000" "503.6000" ...
>
> I want to change the class of df$CREATED.DATE from Chr to Date:
>
>
>>pose$CREATED.DATE=as.Date(pose$CREATED.DATE,"%d/%m/%y")
>
> Here is what I get :
>
> df <-
> structure(list(DESCRIPTION = c("COTTON NO.2 Jul/10", "COTTON NO.2 Jul/10",
> "PALLADIUM Jun/10", "PALLADIUM Jun/10", "SUGAR NO.11 Jul/10",
> "SUGAR NO.11 Jul/10"), CREATED.DATE = structure(c(18395, 18395,
> 18396, 18396, 18392, 18392), class = "Date"), QUANITY = c(1,
> 1, -1, -1, 1, 1), CLOSING.PRICE = c("81.2000", "81.2000", "503.6000",
> "503.6000", "13.8900", "13.8900")), .Names = c("DESCRIPTION",
> "CREATED.DATE", "QUANITY", "CLOSING.PRICE"), row.names = c(NA,
> 6L), class = "data.frame")
>
> Where does the problem comes from?? Maybe from my sytem date ??
>
> TY for any help
>
> __
> 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.
>



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

__
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] as.date

2010-06-01 Thread Erik Iverson



Where does the problem comes from?? Maybe from my sytem date ??


Simply from not reading the options carefully enough, from ?strptime,

 ‘%y’ Year without century (00-99). If you use this on input, which
  century you get is system-specific.  So don't!  Most often
  values 00 to 68 are prefixed by 20 and 69 to 99 by 19 - that
  is the behaviour specified by the 2001 POSIX standard, but it
  does also say ‘it is expected that in a future version of
  IEEE Std 1003.1-2001 the default century inferred from a
  2-digit year will change’.

 ‘%Y’ Year with century.


You want %Y, not %y.

__
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] as.Date question

2009-12-24 Thread Gabor Grothendieck
zzz1 is POSIXct so looking at:

> as.Date.POSIXct
function (x, ...)
{
z <- floor(unclass(x)/86400)
attr(z, "tzone") <- NULL
structure(z, class = "Date")
}


we see as.Date.POSIXct takes the POSIXct object, zzz1, and converts it
to Date relative to GMT.  There is no time zone argument on
as.Date.POSIXct and the time zone specification given to it is
ignored.

On the other hand as.Date.POSIXlt takes the POSIXlt object, zzz2, and
presumably just uses the components in it:

> str(unclass(zzz2))
List of 9
 $ sec  : num 0
 $ min  : int 0
 $ hour : int 0
 $ mday : int 18
 $ mon  : int 2
 $ year : int 99
 $ wday : int 4
 $ yday : int 76
 $ isdst: int 0
 - attr(*, "tzone")= chr "CET"

Note that as.Date.POSIXlt also has not time zone argument so any time
zone argument given to it is also ignored:

> as.Date.POSIXlt
function (x, ...)
.Internal(POSIXlt2Date(x))


Perhaps the unexpected part is that as.Date.POSIXct always converts
relative to GMT so if you want to convert relative to anything else
its best to convert to character representation in the desired time
zone and then convert that to Date.

Also if you are dealing with dates that do not have times its best not
to use POSIXt in the first place.  Date class is a better fit.

See relevant article in R News 4/1.


On Sun, Dec 20, 2009 at 12:18 PM, MAL  wrote:
> All!
>
> This piece of code:
>
> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
> zzz1 == zzz2
> as.Date(zzz1)
> as.Date(zzz2)
>
> yields TRUE for "zzz1==zzz2", but the two dates returned by as.Date are
> different:
>
>> as.Date(zzz1)
>
> [1] "1999-03-17"
>>
>> as.Date(zzz2)
>
> [1] "1999-03-18"
>
> I'm using R 2.10.0.
>
> Would be glad for any clarifications. Thanks!
>
> __
> 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.
>

__
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] as.Date question

2009-12-24 Thread Linlin Yan
I am afraid that although in same literally, they are indeed different
functions: as.Date.POSIXct and as.Date.POSIXlt. But I am not sure why
they are designed like this, which causes the confusion as you
mentioned.

On Thu, Dec 24, 2009 at 11:02 PM, MAL  wrote:
> Mark, not sure that's the answer.
>
> Usually one has x=y --> f(x)=f(y)
>
> which doesn't seem to hold here (put x=zzz1, y=zzz2, f=as.Date()).
>
> Or do I overlook something?
>
>
> - Original Message - From: "Marek Janad" 
> To: 
> Sent: Thursday, December 24, 2009 00:08
> Subject: Re: [R] as.Date question
>
>
>> Look at documentation
>>
>> ?as.Date
>>
>> as.Date first represents time in UTC, what gives:
>>
>> as.POSIXlt(zzz1, tz="UTC")
>>
>> HTH
>>
>> 2009/12/20 MAL :
>>>
>>> All!
>>>
>>> This piece of code:
>>>
>>> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
>>> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
>>> zzz1 == zzz2
>>> as.Date(zzz1)
>>> as.Date(zzz2)
>>>
>>> yields TRUE for "zzz1==zzz2", but the two dates returned by as.Date are
>>> different:
>>>
>>>> as.Date(zzz1)
>>>
>>> [1] "1999-03-17"
>>>>
>>>> as.Date(zzz2)
>>>
>>> [1] "1999-03-18"
>>>
>>> I'm using R 2.10.0.
>>>
>>> Would be glad for any clarifications. Thanks!
>>>
>>> __
>>> 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.
>>>
>>
>>
>>
>> --
>> Marek
>>
>> __
>> 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.
>
> __
> 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.
>

__
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] as.Date question

2009-12-24 Thread MAL

Mark, not sure that's the answer.

Usually one has x=y --> f(x)=f(y)

which doesn't seem to hold here (put x=zzz1, y=zzz2, f=as.Date()).

Or do I overlook something?


- Original Message - 
From: "Marek Janad" 

To: 
Sent: Thursday, December 24, 2009 00:08
Subject: Re: [R] as.Date question



Look at documentation

?as.Date

as.Date first represents time in UTC, what gives:

as.POSIXlt(zzz1, tz="UTC")

HTH

2009/12/20 MAL :

All!

This piece of code:

zzz1 <- as.POSIXct("1999-03-18", tz="CET")
zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
zzz1 == zzz2
as.Date(zzz1)
as.Date(zzz2)

yields TRUE for "zzz1==zzz2", but the two dates returned by as.Date are
different:


as.Date(zzz1)


[1] "1999-03-17"


as.Date(zzz2)


[1] "1999-03-18"

I'm using R 2.10.0.

Would be glad for any clarifications. Thanks!

__
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.





--
Marek

__
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.


__
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] as.Date question

2009-12-23 Thread Marek Janad
Look at documentation

?as.Date

as.Date first represents time in UTC, what gives:

as.POSIXlt(zzz1, tz="UTC")

HTH

2009/12/20 MAL :
> All!
>
> This piece of code:
>
> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
> zzz1 == zzz2
> as.Date(zzz1)
> as.Date(zzz2)
>
> yields TRUE for "zzz1==zzz2", but the two dates returned by as.Date are
> different:
>
>> as.Date(zzz1)
>
> [1] "1999-03-17"
>>
>> as.Date(zzz2)
>
> [1] "1999-03-18"
>
> I'm using R 2.10.0.
>
> Would be glad for any clarifications. Thanks!
>
> __
> 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.
>



-- 
Marek

__
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] as.Date question

2009-12-21 Thread Felix Andrews
I don't know the details of why this is happening, but in any case it
is a good idea to round() your times if you want to convert them to
dates. Just as you would round() a numeric value to convert it to an
integer.

as.Date(round(zzz1, "days"))


2009/12/21 Jason Morgan :
> Hello,
>
> On 2009.12.20 18:06:17, MAL wrote:
>> All!
>>
>> This piece of code:
>>
>> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
>> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
>> zzz1 == zzz2
>> as.Date(zzz1)
>> as.Date(zzz2)
>>
>> yields TRUE for "zzz1==zzz2", but the two dates returned by as.Date are 
>> different:
>>
>> > as.Date(zzz1)
>> [1] "1999-03-17"
>> > as.Date(zzz2)
>> [1] "1999-03-18"
>>
>> I'm using R 2.10.0.
>>
>> Would be glad for any clarifications. Thanks!
>
> I don't know why as.Date() is giving different results, but if look at
> the value of the variables, they are equal:
>
>> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
>> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
>> zzz1 == zzz2
> [1] TRUE
>> as.Date(zzz1)
> [1] "1999-03-17"
>> as.Date(zzz2)
> [1] "1999-03-18"
>> zzz1
> [1] "1999-03-18 CET"
>> zzz2
> [1] "1999-03-18 CET"
>
> Maybe someone here can explain the behavior of as.Date().
>
> Cheers,
> ~Jason
>
>
> --
> Jason W. Morgan
> Graduate Student
> Department of Political Science
> *The Ohio State University*
> 154 North Oval Mall
> Columbus, Ohio 43210
>
> __
> 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.
>



-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andr...@anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/

__
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] as.Date question

2009-12-20 Thread Jason Morgan
Hello,

On 2009.12.20 18:06:17, MAL wrote:
> All!
> 
> This piece of code:
> 
> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
> zzz1 == zzz2
> as.Date(zzz1)
> as.Date(zzz2)
> 
> yields TRUE for "zzz1==zzz2", but the two dates returned by as.Date are 
> different:
> 
> > as.Date(zzz1)
> [1] "1999-03-17"
> > as.Date(zzz2)
> [1] "1999-03-18"
> 
> I'm using R 2.10.0.
> 
> Would be glad for any clarifications. Thanks!

I don't know why as.Date() is giving different results, but if look at
the value of the variables, they are equal:

> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
> zzz1 == zzz2
[1] TRUE
> as.Date(zzz1)
[1] "1999-03-17"
> as.Date(zzz2)
[1] "1999-03-18"
> zzz1
[1] "1999-03-18 CET"
> zzz2
[1] "1999-03-18 CET"

Maybe someone here can explain the behavior of as.Date().

Cheers,
~Jason


-- 
Jason W. Morgan
Graduate Student
Department of Political Science
*The Ohio State University*
154 North Oval Mall
Columbus, Ohio 43210

__
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] as.Date from data.frame

2009-11-11 Thread separent

Hello Gentlemen,

All of your answers were helpfull. Indeed, 'as.is=TRUE' or
'stringsAsFactors=FALSE' avoid importing as factors, as it did when I
imported the table without specifying anything. However, data frames will
not allow different datatypes within a single column, so, for time series, I
should work with a transpose of the table. However, when the time series is
the label of a profile, I should read the table with 'header = TRUE'.

In other words:
* Plotting values of a column (let's say againts observation number) for a
selected time (where time is the name of the series): import data with
'header = TRUE'
* Plotting the evolution of the values for a single observation number
against time: 'header = TRUE' & transpose & 'as.is=TRUE'

Kind Regards,

Serge-Étienne Parent
Golder Associés
Canada



separent wrote:
> 
> #Hello,
> 
> #I loaded data using read.table - I needed to convert a row in the data
> frame to date class:
> 
>> data
> 
> V1  V2  V3  V4
> 1  2008-05-19  2008-04-19  2008-03-21  2008-02-22
> 2 38.16999817 30.7008 36.8661 35.18999863
> 3 37.4754 29.9576 36.4508 35.3661
> 4 37.4754 30.1462 36.47000122 35.3661
> 5 37.84999847 30.5669 36.8415 35.74000168
> 6 38.3839 31.1462 37.3415 36.2746
> 7 39.1161 31.9085 38.02999878 36.9754
> 8 39.81000137 32.65000153 38.6831 37.6339
> 9 40.47000122 33.34999847 39.27999878 38.2746
> 
>> data[1,]
>   V1 V2 V3 V4
> 1 2008-05-19 2008-04-19 2008-03-21 2008-02-22
> 
>> dates1<-as.Date(data[1,])
> 
> do not know how to convert 'dates[1,]' to class "Date"
> 
> # However, I can individually convert them all:
> 
>> dates1.1<-as.Date(data[1,1])
> 
>> dates1.1
> [1] "2008-05-19"
> 
> # How can I change the class of the date over the entire row (my original
> file contains more than one hundred rows)?
> # Thank you very much.
> 

-- 
View this message in context: 
http://old.nabble.com/as.Date-from-data.frame-tp26305830p26307735.html
Sent from the R help mailing list archive at Nabble.com.

__
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] as.Date from data.frame

2009-11-11 Thread David Winsemius


On Nov 11, 2009, at 1:06 PM, separent wrote:



#Hello,

#I loaded data using read.table - I needed to convert a row in the  
data

frame to date class:


You _should_ have given the actual code (as the Posting Guide  
requests), but I would guess that you should have added either  
as.is=TRUE or stringsAsFactors=FALSE. As it is, you probably have all  
factors.





data


V1  V2  V3  V4
1  2008-05-19  2008-04-19  2008-03-21  2008-02-22
2 38.16999817 30.7008 36.8661 35.18999863
3 37.4754 29.9576 36.4508 35.3661
4 37.4754 30.1462 36.47000122 35.3661
5 37.84999847 30.5669 36.8415 35.74000168
6 38.3839 31.1462 37.3415 36.2746
7 39.1161 31.9085 38.02999878 36.9754
8 39.81000137 32.65000153 38.6831 37.6339
9 40.47000122 33.34999847 39.27999878 38.2746


data[1,]

 V1 V2 V3 V4
1 2008-05-19 2008-04-19 2008-03-21 2008-02-22


dates1<-as.Date(data[1,])


do not know how to convert 'dates[1,]' to class "Date"


You should have given the actual error message which was probably more  
informative than what your brain interpreted it to mean.


# However, I can individually convert them all:


dates1.1<-as.Date(data[1,1])



dates1.1

[1] "2008-05-19"

# How can I change the class of the date over the entire row (my  
original

file contains more than one hundred rows)?


Off hand I would say you want to work on a transpose of this data. You  
cannot mix datatypes within columns and it seems fairly clear that the  
rows below number 1 are numeric. Back to the drawing board.



--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] as.Date from data.frame

2009-11-11 Thread Marc Schwartz

On Nov 11, 2009, at 12:06 PM, separent wrote:



#Hello,

#I loaded data using read.table - I needed to convert a row in the  
data

frame to date class:


data


V1  V2  V3  V4
1  2008-05-19  2008-04-19  2008-03-21  2008-02-22
2 38.16999817 30.7008 36.8661 35.18999863
3 37.4754 29.9576 36.4508 35.3661
4 37.4754 30.1462 36.47000122 35.3661
5 37.84999847 30.5669 36.8415 35.74000168
6 38.3839 31.1462 37.3415 36.2746
7 39.1161 31.9085 38.02999878 36.9754
8 39.81000137 32.65000153 38.6831 37.6339
9 40.47000122 33.34999847 39.27999878 38.2746


data[1,]

 V1 V2 V3 V4
1 2008-05-19 2008-04-19 2008-03-21 2008-02-22


dates1<-as.Date(data[1,])


do not know how to convert 'dates[1,]' to class "Date"

# However, I can individually convert them all:


dates1.1<-as.Date(data[1,1])



dates1.1

[1] "2008-05-19"

# How can I change the class of the date over the entire row (my  
original

file contains more than one hundred rows)?
# Thank you very much.


In a data frame, you cannot change the data type for a row, without  
changing the data type for the entire column.


That being said, it looks to me like each column contains continuous  
data for a chronological series.


If that is correct, then you want the dates to be the column names and  
not the first row., Thus, when you used read.table(), you should have  
included the argument 'header = TRUE', which would do just that. With  
read.table(), header is FALSE by default.


HTH,

Marc Schwartz

__
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] as.Date from data.frame

2009-11-11 Thread Steve Lianoglou

Hi,

On Nov 11, 2009, at 1:06 PM, separent wrote:



#Hello,

#I loaded data using read.table - I needed to convert a row in the  
data

frame to date class:


data


V1  V2  V3  V4
1  2008-05-19  2008-04-19  2008-03-21  2008-02-22
2 38.16999817 30.7008 36.8661 35.18999863
3 37.4754 29.9576 36.4508 35.3661
4 37.4754 30.1462 36.47000122 35.3661
5 37.84999847 30.5669 36.8415 35.74000168
6 38.3839 31.1462 37.3415 36.2746
7 39.1161 31.9085 38.02999878 36.9754
8 39.81000137 32.65000153 38.6831 37.6339
9 40.47000122 33.34999847 39.27999878 38.2746


data[1,]

 V1 V2 V3 V4
1 2008-05-19 2008-04-19 2008-03-21 2008-02-22


dates1<-as.Date(data[1,])


I think this should work if data[1,] returns a vector of characters:

R> d <- c("2008-05-19", "2008-05-30")
R> dd <- as.Date(d)
R> is(dd)
[1] "Date" "oldClass"

Is your first row being treated as factors? Maybe if you convert to  
character first it should work?


R> dates1<-as.Date(as.character(data[1,]))

But the fact that it works for as.Date(data[1,1]) make it a bit  
weird ...


-steve


do not know how to convert 'dates[1,]' to class "Date"

# However, I can individually convert them all:


dates1.1<-as.Date(data[1,1])



dates1.1

[1] "2008-05-19"

# How can I change the class of the date over the entire row (my  
original

file contains more than one hundred rows)?
# Thank you very much.
--
View this message in context: 
http://old.nabble.com/as.Date-from-data.frame-tp26305830p26305830.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] 'as.Date' conversion of classes POSIX*t (problem/feature)?

2008-07-03 Thread Gabor Grothendieck
In the development version of R the output
changes to:

> x1 = as.POSIXlt("2008-01-02 00:58:00")
>
> x2 = as.POSIXct("2008-01-02 00:58:00")
>
> as.Date(x1); as.Date(x2)
[1] "2008-01-02"
[1] "2008-01-02"
>
> R.version.string
[1] "R version 2.8.0 Under development (unstable) (2008-06-28 r46012)"



On Thu, Jul 3, 2008 at 6:48 PM, Angel Spassov <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm working with objects of classes "Date","POSIXlt" and "POSIXct" and still
> having some Date/Time-related concepts unclear. In the documentation of
> "as.Date" one can find:
>
> "The 'as.Date' methods accept ... '"POSIXlt"' and '"POSIXct"'. (The last are
> converted to days by ignoring the time after midnight in the representation
> of the time in UTC.)"
>
>
> As far as why "POSIXct" ignores the time after midnight is still open
> question for me and some basic hints about why this happens would be greatly
> appreciated? Having mentioned this one can avoid an eventual confusion when
> interpreting the following:
>
>
>  x1 = as.POSIXlt("2008-01-02 00:58:00")
>
> x2 = as.POSIXct("2008-01-02 00:58:00")
>
> as.Date(x1); as.Date(x2)
>
> [1] "2008-01-02"
>
> [1] "2008-01-01"
>
>
>  which happened to me at the beginning. Aside from this, my real problem was
> with the (very) unexpected behavior of the 'as.data.frame'-function which
> seems to coerce the class '"POSIXlt"' to class '"POSIXct"' and consequently
> making my life considerably harder through:
>
> as.Date(as.data.frame(x1)[1,1])
>
> [1] "2008-01-01"
>
> where
>
> as.Date(x1)
>
> [1] "2008-01-02"
>
>
> Can anyone offer me a strong evidence that exactly this behaviour of R gives
> me advantage over the "naturally" expected conversion to "2008-01-02"?
> Thanks in advance.
>
>[[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.
>

__
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] as.Date() clarification

2008-07-03 Thread Martin Maechler
> "PD" == Peter Dalgaard <[EMAIL PROTECTED]>
> on Thu, 03 Jul 2008 12:07:41 +0200 writes:

[..]

PD> and the help page has the explanation.

[..]

PD> [By the way, there used to be a way to see the current help pages on the
PD> web, but I can't remember how. 

http://stat.ethz.ch/R-manual/   
(I think one of the oldest still working links in the R-project)

where, for  as.Date , as in our question, you may end up here:

http://stat.ethz.ch/R-manual/R-patched/library/base/html/format.Date.html

Martin Maechler, ETH Zurich (i.e. provider of the above)


[]

__
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] as.Date() clarification

2008-07-03 Thread Peter Dalgaard
Ron Michael wrote:
> When I use the code as.Date(0) the I get : "1970-01-01". My question is why 
> it is like that? help file on as.Date seems to give no light on that. Can 
> anyone clarify me?
>   
Which version of R is this?

R version 2.7.1 (2008-06-23)
...
> as.Date(0)
Error in as.Date.numeric(0) : 'origin' must be supplied

and the help page has the explanation.

Internally, Date objects are represented as days since 1970-01-01, and
you can still exploit that with

> structure(0,class="Date")
[1] "1970-01-01"

although you really shouldn't need to have and shouldn't have to use
that knowledge.

[By the way, there used to be a way to see the current help pages on the
web, but I can't remember how. Searching for as.Date via the R search
sites doesn't  help either (interesting set of sponsored links from
Google though...), and the Wiki interface to help pages appears to be
broken.]
>  
> Regards,
>
> Send instant messages to your online friends http://uk.messenger.yahoo.com 
>   [[alternative HTML version deleted]]
>   

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
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] as.Date() clarification

2008-07-03 Thread Achim Zeileis

On Thu, 3 Jul 2008, Ron Michael wrote:

When I use the code as.Date(0) the I get : "1970-01-01". My question is 
why it is like that? help file on as.Date seems to give no light on 
that. Can anyone clarify me?


In R, "Date" objects are stored internally as the number of days since 
1970-01-01 (typically the epoch on Unix systems):


## today
dd <- as.Date("2008-07-03")
dd

## number of days since 1970-01-01
dn <- as.numeric(dd)
dn

## In base R, you can reverse this if you specify the origin used
as.Date(dn, origin = "1970-01-01")

## If you load package "zoo", this is made the default
library("zoo")
as.Date(dn)

The idea of the zoo implementation is that you can switch back and forth 
between the "Date" and numeric representation. The implementation in base 
R, on the other hand, wants to be agnostic to the origin used and hence 
sets no default for that argument.


hth,
Z



 
Regards,

Send instant messages to your online friends http://uk.messenger.yahoo.com
[[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] as.date - german date format

2008-01-10 Thread Konga

Hi Terry,

thanks for the information, I should know this in advance but I´m not used
to case sensitive syntax - thanks Delphi... 

regards,
Eric Will


Terry Therneau wrote:
> 
>>> Konga wrote:
 Hi,

 I have a data.frame with the following variable:
 $  xx  :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3
 3
 3

 now I?d like use "as.date" on it - if I comprehend the instructions on
 http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html
 it should work like this:

 as.date(xx, "%d.%m.%Y") - but it doesn?t...
>>> What is the error message? 
>>> - Fehler in as.date(mydata$xx, "%d.%m.%Y") : 
>>>   Cannot coerce to date format
>  
>   You are invoking a function from the "date" library, but reading
> the documentation for "Date"; they are quite different.
> 
>   The 'date' library was written 8-10 years ago, and is used by some of
> the
> functions in the survival library (a dependence that I am currently
> removing).
> It works quite well, but has a much smaller scope of functionality than
> the 
> later 'Date' library, in particular there are no attempts at
> multi-language
> support.  So as.date + German format is nearly a contradiction.  
> 
>   > args(as.date)
>   function (x, order = "mdy", ...) 
>   
> So you see that the function does not even have a "format" argument.  If
> your
> delimiter were one of /,-  then order='dmy' would have worked, but as.date
> does 
> not accept '.'
> 
>   Terry Therneau
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/as.date---german-date-format-tp14734166p14737513.html
Sent from the R help mailing list archive at Nabble.com.

__
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] as.date - german date format

2008-01-09 Thread Konga


Thanks a lot, it works!

Now I have to find out why - but I think I can/should do it on my own ;o)


-- 
View this message in context: 
http://www.nabble.com/as.date---german-date-format-tp14712654p14728914.html
Sent from the R help mailing list archive at Nabble.com.

__
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] as.date - german date format

2008-01-09 Thread John Kane
"Functions to convert between character
representations and objects of class "Date"
representing calendar dates."

 $  xx  :Factor w/ 66 levels

try as.character(xx)


--- Konga <[EMAIL PROTECTED]> wrote:

> 
> Hi,
> 
> I have a data.frame with the following variable:
> $  xx  :Factor w/ 66 levels
> "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 3
> 
> now I´d like use "as.date" on it - if I comprehend
> the instructions on
>
http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html
> it should work like this:
> 
> as.date(xx, "%d.%m.%Y") - but it doesn´t...
> 
> the survival Package ist loaded - is there a problem
> with the german format?
> Or did I understand something wrong?
> 
> Much better than tranforming the format from to data
> would be to import it
> in the right format.
> Is there a parameter for read.csv to get it as a
> date from the beginning?
> 
> 
> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/as.date---german-date-format-tp14712654p14712654.html
> Sent from the R help mailing list archive at
> Nabble.com.
> 
> __
> 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.
>

__
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] as.date - german date format

2008-01-09 Thread Uwe Ligges


Konga wrote:
> 
> Uwe Ligges-3 wrote:
>>
>>
>> Konga wrote:
>>> Hi,
>>>
>>> I have a data.frame with the following variable:
>>> $  xx  :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3
>>> 3
>>>
>>> now I´d like use "as.date" on it - if I comprehend the instructions on
>>> http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html
>>> it should work like this:
>>>
>>> as.date(xx, "%d.%m.%Y") - but it doesn´t...
>> What is the error message? 
>> - Fehler in as.date(mydata$xx, "%d.%m.%Y") : 
>>   Cannot coerce to date format

I see, so this is really as.data() from the survival package.

>> Which R version is this? 
>> -2.6.0
>>
>> What are all the 
>> labels (in order to reproduce your error)?
>> - The data.frame has 1500 objects - do you want me to print them all? Even
>> the 66 different levels of the factor would be a little bit much, I think.
>> But I printed them once, they all have the same format.

The data.frame has 1500 rows but the factor just 66 labels. You could 
have made it available from some web server.

Anyway, you could try

   as.date(format(as.Date(mydata$xx, "%d.%m.%Y"), "%m/%d/%Y"))

instead (discussion open for better ideas!).


Uwe Ligges


>>
>>
>> in order to get better help.
>>
>> Uwe Ligges
>>
>>
>>
>>> the survival Package ist loaded - is there a problem with the german
>>> format?
>>> Or did I understand something wrong?
>>>
>>> Much better than tranforming the format from to data would be to import
>>> it
>>> in the right format.
>>> Is there a parameter for read.csv to get it as a date from the beginning?
>>>
>>>
>>>
>>>
>> __
>> 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.
>>
>>
>

__
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] as.date - german date format

2008-01-09 Thread Konga


Uwe Ligges-3 wrote:
> 
> 
> 
> Konga wrote:
>> Hi,
>> 
>> I have a data.frame with the following variable:
>> $  xx  :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3
>> 3
>> 
>> now I´d like use "as.date" on it - if I comprehend the instructions on
>> http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html
>> it should work like this:
>> 
>> as.date(xx, "%d.%m.%Y") - but it doesn´t...
> 
> What is the error message? 
> - Fehler in as.date(mydata$xx, "%d.%m.%Y") : 
>   Cannot coerce to date format
> 
> Which R version is this? 
> -2.6.0
> 
> What are all the 
> labels (in order to reproduce your error)?
> - The data.frame has 1500 objects - do you want me to print them all? Even
> the 66 different levels of the factor would be a little bit much, I think.
> But I printed them once, they all have the same format.
> 
> 
> 
> 
> 
> 
> in order to get better help.
> 
> Uwe Ligges
> 
> 
> 
>> the survival Package ist loaded - is there a problem with the german
>> format?
>> Or did I understand something wrong?
>> 
>> Much better than tranforming the format from to data would be to import
>> it
>> in the right format.
>> Is there a parameter for read.csv to get it as a date from the beginning?
>> 
>> 
>> 
>>
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/as.date---german-date-format-tp14712654p14714199.html
Sent from the R help mailing list archive at Nabble.com.

__
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] as.date - german date format

2008-01-09 Thread Uwe Ligges


Konga wrote:
> Hi,
> 
> I have a data.frame with the following variable:
> $  xx  :Factor w/ 66 levels "01.02.2006","01.03.2006",..: 3 3 3 3 3 3 3 3 3
> 
> now I´d like use "as.date" on it - if I comprehend the instructions on
> http://finzi.psych.upenn.edu/R/library/base/html/format.Date.html
> it should work like this:
> 
> as.date(xx, "%d.%m.%Y") - but it doesn´t...

At least as.Date() works for me for *one* of your factor labels:

as.Date(factor("01.02.2006"), "%d.%m.%Y")
[1] "2006-02-01"

So, please read the posting guide before posting and learn that you 
should tell us:

What is the error message? Which R version is this? What are all the 
labels (in order to reproduce your error)?

in order to get better help.

Uwe Ligges



> the survival Package ist loaded - is there a problem with the german format?
> Or did I understand something wrong?
> 
> Much better than tranforming the format from to data would be to import it
> in the right format.
> Is there a parameter for read.csv to get it as a date from the beginning?
> 
> 
> 
>

__
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.