Dear all I would like to ask you if an assignment can be done inside a lapply
statement.
For example
I would like to covert a double nested for loop
for (i in c(1:dimx)){
for (j in c(1:dimy)){
Powermap[i,j] - Pr(c(i,j),c(PRX,PRY),f)
}
}
to something like that:
unlist(lapply(1:nrow(ij),function(rowId) { return
(Powermap[i,j]-Pr(c(ij$i[rowId],ij$j[rowId]),c(PRX,PRY),f)) }))lapply
actually catches each return value of the excuted function.
here your function actually returns nothing if the assignment succeeds.
If your purpose for the call to Pr is
-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Alaios
Sent: woensdag 27 april 2011 11:37
To: R-help@r-project.org
Subject: [R] Assignments inside lapply
Dear all I would like to ask you if an assignment can be done inside a
lapply statement.
For example
I would
/264.59.36
-- Do Not Disapprove
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Alaios
Sent: woensdag 27 april 2011 11:37
To: R-help@r-project.org
Subject: [R] Assignments inside lapply
Dear all I would like to ask you
-project.org
Onderwerp: [R] Assignments inside lapply
Dear all I would like to ask you if an assignment can be done
inside a lapply statement.
For example
I would like to covert a double nested for loop
for (i in c(1:dimx)){
for (j in c(1:dimy)){
Powermap[i,j] - Pr(c(i,j),c(PRX,PRY),f
try this out?
Best Regards
Alex
--- On Wed, 4/27/11, ONKELINX, Thierry thierry.onkel...@inbo.be wrote:
From: ONKELINX, Thierry thierry.onkel...@inbo.be
Subject: RE: [R] Assignments inside lapply
To: Alaios ala...@yahoo.com, R-help@r-project.org R-help@r-project.org
Date: Wednesday, April 27
that a reasonable answer can be extracted from a given body of data.
~ John Tukey
-Oorspronkelijk bericht-
Van: Alaios [mailto:ala...@yahoo.com]
Verzonden: woensdag 27 april 2011 12:14
Aan: R-help@r-project.org; ONKELINX, Thierry
Onderwerp: RE: [R] Assignments inside lapply
I would like to use
On Wed, Apr 27, 2011 at 10:12 PM, Kenn Konstabel lebats...@gmail.com wrote:
On Wed, Apr 27, 2011 at 12:58 PM, Nick Sabbe nick.sa...@ugent.be wrote:
No, that does not work.
You cannot do assignment within (l)apply.
Nor in any other function for that matter.
Yes that may work if you want to.
8 matches
Mail list logo