integrating multi-dimensional dat along one dimension

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

integrating multi-dimensional dat along one dimension

Cable, Sam B Civ USAF AFMC AFRL/RVBXI
I just want to integrate a 3D data set along one dimension to obtain a
2D data set.  Something like:

 

(given array "d" with dim nx,ny,nz ...)

 

data_int<-array(dim=c(nx,ny))

for (n in 1:ny) {

  for (m in 1:nx) {

     data_int[m,n]<-sum(d[m,n,])

  }

}

 

The thing is, given R's facility with integers, it seems that I should
be able to obtain data_int without the explicit for-loops, but I haven't
been able to figure out how to do it.  Anyone know how?  Thanks.


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: integrating multi-dimensional dat along one dimension

David Carlson
set.seed(42)
d <- array(as.integer(round(runif(125)*10, 0)), dim=c(5, 5, 5))
data_int <- apply(d, c(1,2), sum)

-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352


----- Original Message -----

From: "Sam B Civ USAF AFMC AFRL Cable/RVBXI" <[hidden email]>
To: [hidden email]
Sent: Friday, July 13, 2012 4:11:28 PM
Subject: [R] integrating multi-dimensional dat along one dimension

I just want to integrate a 3D data set along one dimension to obtain a
2D data set. Something like:



(given array "d" with dim nx,ny,nz ...)



data_int<-array(dim=c(nx,ny))

for (n in 1:ny) {

for (m in 1:nx) {

data_int[m,n]<-sum(d[m,n,])

}

}



The thing is, given R's facility with integers, it seems that I should
be able to obtain data_int without the explicit for-loops, but I haven't
been able to figure out how to do it. Anyone know how? Thanks.


[[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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.

______________________________________________
[hidden email] mailing list
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.