Kaptue Tchuente, Armel
2013-Jun-28 03:04 UTC
[R] How to create a function returning an array ?
Hi there,
I would like to know how to change the line "img=as.single(rnorm(m)))"
such that instead of being a vector of length m as it is now, img is an array of
dimension c=(n,m,o) for instance
---------------------------------
read_ts<-function(n,m,o,img) {
out<-.Fortran("read_ts",
as.integer(n),
as.integer(m),
as.integer(o),
img=as.single(rnorm(n)))
return(out$img)
------------------------------------------
Cheers
Armel
[[alternative HTML version deleted]]
On Jun 27, 2013, at 8:04 PM, Kaptue Tchuente, Armel wrote:> Hi there, > > I would like to know how to change the line "img=as.single(rnorm(m)))" such that instead of being a vector of length m as it is now, img is an array of dimension c=(n,m,o) for instance > > --------------------------------- > read_ts<-function(n,m,o,img) { > out<-.Fortran("read_ts", > as.integer(n), > as.integer(m), > as.integer(o), > img=as.single(rnorm(n))) > return(out$img) > ------------------------------------------ >Well, assuming that the 'out$img' object has a R-length of n*m*o , wouldn't if be simpler to just change the return call to: return( array( out$img, dim=c(n,m,o) ) I don't think you wnat start naming your dimension vectors "c". -- David Winsemius Alameda, CA, USA