Hi Jim,
by dropping them down it gives 1 day less than it should do, on all timezone
notations CEST and CET.
> start
[1] "2002-09-04 CEST" "2000-07-27 CEST" "2003-01-04
CET" "2001-06-29 CEST"
"2005-01-12 CET" "2000-05-28 CEST" "2002-06-01
CEST" "2000-06-02 CEST"
"2000-02-27 CET" "2000-09-29 CEST" "2003-10-22
CEST" "2002-06-03 CEST"
[13] "2004-12-30 CET" "2000-04-07 CEST" "2006-02-03
CET" "2003-06-12 CEST"
"2004-07-15 CEST" "2000-04-29 CEST" "2000-05-06
CEST" "2004-10-27 CEST"
> start <-
format(as.Date(start,"%Y-%m-%d"),"%Y-%m-%d")
> start
[1] "2002-09-03" "2000-07-26" "2003-01-03"
"2001-06-28" "2005-01-11"
"2000-05-27" "2002-05-31" "2000-06-01"
"2000-02-26" "2000-09-28"
"2003-10-21" "2002-06-02" "2004-12-29"
"2000-04-06" "2006-02-02"
"2003-06-11" "2004-07-14"
[18] "2000-04-28" "2000-05-05" "2004-10-26"
2011/7/12 Jim Lemon <jim@bitwrit.com.au>
> On 07/12/2011 08:58 PM, B Laura wrote:
>
>> Hello all,
>>
>> Could someone help me with the time zones in understandable&
practical
>> way?
>> I got completely stucked with this.
>>
>> Have googled for a while and read the manuals, but without solutions...
>>
>>
>>
>> ------------------------------**------------------------------**-------
>>
>> When data imported from Excel 2007 into R (2.13)
>>
>> all time variables, depending on date (summer or winter) get (un-asked
for
>> it!) a time zone addition CEST (for summer dates) or CET (for winter
>> dates).
>>
>>
>>
>> Dataset
>>>
>> Start End1 End2
>> days2End1.from.Excel days2End2.from.Excel
>> days2End1.in.R days2End2.in.R
>> 1 2010-01-01 2011-01-01 2012-01-01
>> 365 730
>> 365 days 730.0000 days
>> 2 2010-02-01 2011-02-01 2012-01-01
>> 365 699
>> 365 days 699.0000 days
>> 3 2010-03-01 2011-03-01 2012-01-01
>> 365 671
>> 365 days 671.0000 days
>> 4 2010-04-01 2011-04-01 2012-01-01
>> 365 640
>> 365 days 640.0417 days
>> 5 2010-05-01 2011-05-01 2012-01-01
>> 365 610
>> 365 days 610.0417 days
>> 6 2010-06-01 2011-06-01 2012-01-01
>> 365 579
>> 365 days 579.0417 days
>> 7 2010-07-01 2011-07-01 2012-01-01
>> 365 549
>> 365 days 549.0417 days
>> 8 2010-08-01 2011-08-01 2012-01-01
>> 365 518
>> 365 days 518.0417 days
>> 9 2010-09-01 2011-09-01 2012-01-01
>> 365 487
>> 365 days 487.0417 days
>> 10 2010-10-01 2011-10-01 2012-01-01
>> 365 457
>> 365 days 457.0417 days
>> 11 2010-11-01 2011-11-01 2012-01-01
>> 365 426
>> 365 days 426.0000 days
>> 12 2010-12-01 2011-12-01 2012-01-01
>> 365 396
>> 365 days 396.0000 days
>>
>> Dataset$Start
>>>
>> [1] "2010-01-01 CET" "2010-02-01 CET"
"2010-03-01 CET" "2010-04-01
>> CEST"
>> "2010-05-01 CEST" "2010-06-01 CEST"
"2010-07-01 CEST" "2010-08-01 CEST"
>> "2010-09-01 CEST" "2010-10-01 CEST"
"2010-11-01 CET" "2010-12-01 CET"
>>
>> Dataset$End1
>>>
>> [1] "2011-01-01 CET" "2011-02-01 CET"
"2011-03-01 CET" "2011-04-01
>> CEST"
>> "2011-05-01 CEST" "2011-06-01 CEST"
"2011-07-01 CEST" "2011-08-01 CEST"
>> "2011-09-01 CEST" "2011-10-01 CEST"
"2011-11-01 CET" "2011-12-01 CET"
>>
>> Dataset$End2
>>>
>> [1] "2012-01-01 CET" "2012-01-01 CET"
"2012-01-01 CET" "2012-01-01 CET"
>> "2012-01-01 CET" "2012-01-01 CET" "2012-01-01
CET" "2012-01-01 CET"
>> "2012-01-01 CET" "2012-01-01 CET" "2012-01-01
CET" "2012-01-01 CET"
>>
>>
>>
>> Variables 'days2End1.from.Excel and 'days2End2.from.Excel'
are
>> calculated
>> in Excel.
>>
>>
>>
>> Same calculation (with same outcome!) I would like to be able to
perform
>> with R.
>>
>>
>>
>> Variables 'days2End1.in.R' and 'days2End2.in.R are
calculated with R.
>>
>>
>>
>> Dataset$days2End1.from.Excel
>>>
>> [1] 365 365 365 365 365 365 365 365 365 365 365 365
>>
>>
>>
>> Dataset$days2End1.in.R<- with(Dataset, End1- Start)
>>>
>>
>> Dataset$days2End1.in.R
>>>
>>
>>
>> Time differences in days
>> [1] 365 365 365 365 365 365 365 365 365 365 365 365
>> attr(,"tzone")
>> [1] ""
>>
>>
>> Dataset$days2End2.from.Excel
>>>
>> [1] 730 699 671 640 610 579 549 518 487 457 426 396
>>
>>
>>
>> Dataset$days2End2.in.R<- with(Dataset, End2- Start)
>>>
>>
>>
>>
>> Dataset$days2End2.in.R
>>>
>> Time differences in days
>> [1] 730.0000 699.0000 671.0000 640.0417 610.0417 579.0417 549.0417
>> 518.0417
>> 487.0417 457.0417 426.0000 396.0000
>> attr(,"tzone")
>> [1] ""
>>
>>
>>
>> Quastion 1:
>>
>>
>>
>> As you can see 'Dataset$days2End2.in.R' gives wrong
'day' calculation at
>> time period April until October, when CEST (summer) times are recorded
>>
>> 640.0417 610.0417 579.0417 549.0417 518.0417 487.0417 457.0417
>>
>> giving decimals on days, where round days expected (640 610 579 549 518
>> 487
>> 457).
>>
>>
>>
>>
>>
>> Can someone explain me how to deal with it in R?
>>
>> What is the best way to calculate days in R getting correct
calculations?
>>
>>
>>
>> Question 2:
>>
>>
>>
>> As I only need to work with dates without time and without time zones,
I
>> would be happy to remove them if possible.
>>
>> I tried already the trunc() function but without succes. The result
>> doesn't
>> change.
>>
>>
>>
>> Dataset$days2End2.in.R.TRUNC<- with(Dataset, trunc(End2)-
trunc(Start))
>>>
>>
>> Dataset$days2End2.in.R.TRUNC
>>>
>> Time differences in days
>> [1] 730.0000 699.0000 671.0000 640.0417 610.0417 579.0417 549.0417
>> 518.0417
>> 487.0417 457.0417 426.0000 396.0000
>> attr(,"tzone")
>> [1] ""
>>
>>
>>
>>
>> Hi Laura,
> I have just solved one Excel export problem, so I'll have a go at this
one.
> Try this:
>
>
Dataset$Start<-format(as.Date(**Dataset$Start,"%Y-%m-%d"),"%Y-**%m-%d")
>
>
> This may drop the time zone. Excel (and other MS apps) are forever trying
> to do what they think you want when it is not what you want.
>
> Jim
>
[[alternative HTML version deleted]]