[R] need help with matrix manipulation

From: Jaramillo, Renee <rjaramillo_at_constellagroup.com>
Date: Tue 06 Dec 2005 - 06:03:02 EST

I hope my problem is not too basic to post here. I am a beginner having problems with some matrix manipulation. The data I am working with are sites with hourly ozone readings and is in a matrix where each row is a site and each column is an hourly reading. So for 10 sites, one day's worth of data is a 10x24 matrix - column 1 is the ozone measurement for midnight GMT, column 2 is ozone at 1:00am GMT, etc.  

My challenge is that I want to create a new matrix with the same sites, BUT I want the first column to be the hourly ozone reading at midnight LOCAL time. If all the sites were in the same time zone this would be easy - for the US Eastern time zone I could do something like:

oz.est[, 1:19] <- oz.gmt[, 6:24]  

The problem is the sites are in different time zones, and I have a separate vector that indicates which site belongs to which time zone. So sites in the Eastern time zone I want to extract columns 6-24 from the GMT matrix, sites in the Central time zone I want to extract columns 7-24 from the GMT matrix, etc.  

Is there a clever way to use matrix indices on my GMT matrix to extract the columns I need for the sites in the different time zones? I have been trying different things like this:  

start.hr <- c(6,7,6,8,7,5,7,6,5,6)  

oz.local[ , 1: (24-start.hr) ] <- oz.gmt [, (start.hr+1) : 24 ]  

oz.local[ , rep(1,nrow(oz.gmt)) : (24-start.hr) ] <- oz.gmt [, (start.hr+1) : rep(24,nrow(oz.gmt)) ]  

Ultimately I will be working with over 10,000 sites and hourly data over 3 months so my data matrix will be something like 10,220 x 2208    

I'd appreciate any suggestions. Thanks!

Renee Jaramillo          

        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Dec 06 06:12:36 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:28 EST