[R] How to speed up the simulation when processing time and date

2015-01-15 Thread Faranak Golestaneh
Dear Friends,


I am trying to program a forecasting method in R. The predictors are
weather variables in addition to lag measured Power values. The accuracy of
data is one minute and their corresponding time and date are available.

To add lag values of power to the predictors list, I am aiming to consider
last ten minutes values. If I was sure that the database is perfect and the
values for all minutes throughout the year are available I could simply
shift the Power columns but as it may not be always the case, I have used
the following codes for each time t to check if all its corresponding ten
minutes lag values are available and extract them and store in a matrix.
The problem is that, the process is highly time consuming and it takes a
long time to be simulated. Here I ve given reproducible example. I was
wondering any of you can suggest a better approach. Thank you.



rm(list = ls())

cat(\014)



st=2012/01/01

et=2012/02/27



st - as.POSIXlt(as.Date(st))

et - as.POSIXlt(as.Date(et))

time= seq(from=st, to=et,by=60)

timeas.POSIXlt(time)

#Window is the number of lag values

#leadTime is look-ahead time (forecast horizon)

leadTime=10;

Window=15;



=time[1:8000]

Total_Zone1=abind(matrix(rnorm(4000*2),4000*2,1),
matrix(rnorm(4000*2),4000*2,1), matrix(rnorm(4000*2),4000*2,1),time[1:8000])

N_Train=nrow(Total_Zone1);

lag_Power=matrix(0,N_Train,Window)

colnames(Total_Zone1) - c( airtemp,humidity,  Power, time)

Total_Zone1- as.data.frame(Total_Zone1)

for (tt in 4000:N_Train){

  Statlag=Total_Zone1$time[tt]-(leadTime+Window)*60

  EndLag=Total_Zone1$time[tt]-(leadTime)*60

  Index_lags=which((Total_Zone1$timeStatlag)(Total_Zone1$time=EndLag))

  if (size(Index_lags)[2]Window) {

Statlag2=Total_Zone1$time[tt]-24*60*60

Index_lags2=which(Total_Zone1$time==Statlag2)

tem1=rep(Total_Zone1[Index_lags2,c(Power)],Window-size(Index_lags)[2])

lag_Power[tt,]=t(c(Total_Zone1[Index_lags,c(Power)],tem1))

  }else{

 lag_Power[tt,]=t(Total_Zone1[Index_lags,c(Power)])

  }

}

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


[R] Changing UTC time to a time zone different from system time zone

2014-12-28 Thread Faranak Golestaneh
Dear Friends, I’ve just started using R. I am working on a database
containing date-time as well as numeric values. Firstly I have changed the
class of the data/time column from factor to POSIXlt. Time and date are
based on UTC time but I need to change them to a local time ( not my local
time, my zone is Singapore but the data are from Australia) so I need to
change the time and date to Australia time say e.g AEST. I tried one way or
another but all failed. The following is example of the command I used.
Also one of my .CSV files is attached.

Data_Power - read.table(train15.csv,header = TRUE, sep = ,, row.names
= NULL);

Date_clm=Data_Power$TIMESTAMP;

Date_original - strptime(Date_clm, %Y %m %d %H:%M, tz=GMT)

Date_local =format(Date_original, format=%c, tz=America/New_York)

Date_local - strptime(Date_original, %Y %m %d %H:%M +0800)

Date_local=as.POSIXlt(Date_original, Australia/Darwin)

Date_local=as.POSIXlt(Date_original,  AEST )

I would be so thankful if you help me out. Thanks



Cheers,

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