Please help me build a matrix from the vector returned by a function!
I wrote a function that returns two values. An abbreviated version of the
function is shown below:
f<-function(n, v, StD1, aM1, StD2, aM2)
{
out <- array(dim = c(1, 2))
out[1, 1] = xx
out[1, 2] = 2
return(out)
}
I call the function using lapply
values <- array(data = lapply(1:N, h, v, StD1, aM1, StD2, aM2),
dim= c(N, 2))
I want to create a 2xN matrix VALUES such that the first column of VALUES
contains
OUT[1,1], the second column contains OUT[1,2]. Each row of VALUES is to
contain the two values returned by each call to H
i.e. lapply will be run 1:N times. The first time H is called by lapply,
VALUES will contain:
[,1] [,2]
[1,] OUT[1,1] OUT[1,2]
[2,] NULL NULL
.... .... ....
[N,] NULL NULL
After the last time H is called by lapply the matrix will be full, i.e.
[,1] [,2]
[1,] OUT[1,1] OUT[1,2]
[2,] OUT[1,1] OUT[1,2]
.... .... ....
[N,] OUT[1,1] OUT[1,2]
All I need is the final, complete matrix VALUES, I do not need the matrix
in its intermediate state.
Any suggestions would be appreciated.
I am running SPlus 6.1 Professional on a Win 2K platform.
Many thanks,
John
John Sorkin MD, PhD
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC and
University of Maryland School of Medicine Claude Pepper OAIC
410-605-7119
john@grecc.umaryland.edu
Confidentiality Notice: This email message, including any attachments, is for
the sole use of the intended recipient(s) and may contain confidential and
privileged information. Any unauthorized use, disclosure or distribution is
prohibited.
If you are not the intended recipient, please contact the sender by replying to
this e-mail and destroy all copies of the original message.
<University of Maryland, Baltimore Department of Medicine>
|