r - How to compute integral of an array -


i wondering if there way perform integral on arrays in r. have arrays s , r. want integrate them on pressure level (p) 1000 850. how can this?

enter image description here.

the s, r , p data are

s<-structure(c(0.0011979939772106, 0.0011979939772106, 0.0011979939772106,  0.00122851820731487, 0.00122654890214685, 0.00122457959697883,  0.00124164690843498, 0.00123705186304294, 0.0012324568176509,  0.00133617355649982, 0.00133617355649982, 0.00133617355649982,  0.00138048292278021, 0.00137752896502818, 0.00137457500727616,  0.00140575567243643, 0.00139951953940438, 0.00139328340637232,  0.00139820666929237, 0.00139820666929237, 0.00139820666929237,  0.00151308280409338, 0.00150192340814128, 0.00149076401218919,  0.00155575108273376, 0.00154426346925366, 0.00153277585577356 ), .dim = c(3l, 3l, 3l)) 
r<-structure(c(-15.1752538162522, -15.1929331135921, -15.2092524649828,  -16.2142525214608, -16.2400914944961, -16.2604906837345, -17.2355719293295,  -17.2641307942633, -17.2858899294509, -13.3842050011216, -13.4059641363092,  -13.4250033795984, -14.3266475439352, -14.3361671655798, -14.3402470034274,  -15.3466070058547, -15.3398072761085, -15.3262078166163, -10.7132711568418,  -10.7350302920294, -10.7554294812678, -11.8379464568517, -11.8066677000195,  -11.7726690512888, -13.8003484615847, -13.7187517046312, -13.6317151638807 ), .dim = c(3l, 3l, 3l)) 
p<-c(1000,950,900,850) 

i tried following , not figure out how can perform integral array.

f <- function(x) {x} inr <- integrate(f,1000,850) #where f function. 

i not entirely sure asking, there 2 common answers when dealing arrays , integration. first 1 vectorization issue can dealt doing following:

intfunc <- function(x,y) {   sum(x-y) } intfunc(1:5,c(0,0)) warning message:   in x - y :    longer object length not multiple of shorter object length integrate(vectorize(intfunc,vectorize.args = 'x'), upper = 1000, lower = 850, y = r) 3803862 absolute error < 4.2e-08 

this question has been answered elsewhere on stackoverflow:

how pass vector integrate function

r, integrate @ each point of array


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -