anna
2010-Jan-26 19:47 UTC
[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? -- View this message in context: http://n4.nabble.com/Apply-a-function-on-an-array-with-the-parameter-as-an-array-tp1310834p1310834.html Sent from the R help mailing list archive at Nabble.com.
Bert Gunter
2010-Jan-26 19:54 UTC
[R] Apply a function on an array with the parameter as an array
-----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
Bert Gunter
2010-Jan-26 20:00 UTC
[R] Apply a function on an array with the parameter as an array
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
jim holtman
2010-Jan-26 21:19 UTC
[R] Apply a function on an array with the parameter as an array
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:> > Ok, I read the entire posting guide and updated my signature. So I come back > on my question, should I use an apply in an apply to make this? > > ----- > Anna Lippel > -- > View this message in context: http://n4.nabble.com/Apply-a-function-on-an-array-with-the-parameter-as-an-array-tp1310834p1310922.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?