Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

[R] need help with matrix manipulation

Jaramillo, Renee

2005-12-05

Replies:

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:



# VECTOR WITH HOUR TIME DIFFERENCE BETWEEN SITE AND GMT

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



# THIS DOESN'T WORK

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



# THIS DOESN'T WORK EITHER

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@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
©2008 r-help.com - Jax Systems, LLC, U.S.A.