Skip to content

Apply a function on an array with the parameter as an array

9 messages · Bert Gunter, anna, jim holtman +1 more

#
Hello R buddies, I want to apply a function on an array but for each element
of the array I want to use a different parameter, So here is how I tried to
enter the function:
apply(as.matrix(X),2, function, parameter1 = arrayOfParameter)
I put X as a matrix because it was initially an element of a list. It
returns me an array with the same length as X but with values that I don't
even understand...Can someone please help me?
#
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of anna
Sent: Tuesday, January 26, 2010 11:48 AM
To: r-help at r-project.org
Subject: [R] Apply a function on an array with the parameter as an array


Hello R buddies, I want to apply a function on an array but for each element
of the array I want to use a different parameter, So here is how I tried to
enter the function:
apply(as.matrix(X),2, function, parameter1 = arrayOfParameter)
I put X as a matrix because it was initially an element of a list. It
returns me an array with the same length as X but with values that I don't
even understand...Can someone please help me?


-- Probably not. You haven't read and followed the posting guide and
provided a small reproducible example so we know exactly what you tried to
do.

Bert Gunter
Genentech Nonclinical Statistics
#
No the posting guide is quite big and I wanted to take time to read it
properly, since I have been posting seriously since last wednesday and I
work a lot I didn't get time to do it but will do it now ;). So you say that
you know exactly what I tried to do can you explain what I tried to do if
it's not looking for help?
#
I perhaps should have added that the etiquette of this list is to supply
your correct name in your signature. This does not necessarily mean that you
will be ignored if you fail to do so, but it does increase the likelihood
that you will be.


Bert Gunter
Genentech Nonclinical Biostatistics
#
Speaking **only for myself**, if you don't have the time to read and follow
the posting guide, I don't have the time to try to help you.

Bert Gunter
Genentech Nonclinical Biostatistics
#
You can do something like this:

lapply(1:nrow(X), function(.indx, param){
    X[.indx,] * param[.indx]  # apply param[i] to row i of X
}, param=arrayOf Params)
On Tue, Jan 26, 2010 at 3:52 PM, anna <lippelanna24 at hotmail.com> wrote: