Skip to content
Back to formatted view

Raw Message

Message-ID: <BAY135-W13270B8311F5E1CB1D456F88620@phx.gbl>
Date: 2010-01-22T16:32:38Z
From: Steve Murray
Subject: Looping multiple dimensions

Dear all,

I have 30 arrays, each with dimensions 720,360,12. The naming format for each of these 30 objects is: mrunoff_5221, mrunoff_5222... mrunoff_5250.


For example:
> str(mrunoff_5221)
? num [1:720, 1:360, 1:12] NA NA NA NA NA NA NA NA NA NA ...? (the initial NA's are nothing to worry about)


I am looking for a way by which I can extract each of the third dimension of these grids (1:12) in turn, along with the first and second dimensions, to create new objects in the following style:


#2071
mrunoff_207101 <- mrunoff_5221[,,1]
mrunoff_207102 <- mrunoff_5221[,,2]
mrunoff_207103 <- mrunoff_5221[,,3]
mrunoff_207104 <- mrunoff_5221[,,4]
mrunoff_207105 <- mrunoff_5221[,,5]?? ...(etc. - up to [,,12])

#2072
mrunoff_207201 <- mrunoff_5222[,,1]
mrunoff_207202 <- mrunoff_5222[,,2]
mrunoff_207203 <- mrunoff_5222[,,3]
mrunoff_207204 <- mrunoff_5222[,,4]
mrunoff_207205 <- mrunoff_5222[,,5]? ...(etc. - up to [,,12]) and mrunoff_ continues to 2100 and 5250 respectively.


Clearly, this is a cumbersome and non-sustainable way to proceed! There will be 360 new objects in total, and I imagine that there must be a more effective way of achieving this, either via a loop or, possibly, one of the 'apply' functions. Yet my attempts to date have so far resulted in... well, a complete mess!

If anyone has any suggestions as to a more efficient means of achieving this, then I'd be very grateful to hear them.

Many thanks,

Steve

 		 	   		  
_________________________________________________________________
Tell us your greatest, weirdest and funniest Hotmail stories