Hi All, I am trying to make a loop for a function and I am using the
following codes. "p" and "var" are some matrix obtained
before. I would like
to apply the function "gpdlow" for i in 1:12 and get the
"returnlow" for i
in 1:12. But when I ask for "returnlow" there are warnings and it
turns out
some strange result.
for (i in 1:12){
gpdlow <- function(u){
p[,i]$beta -u*p[,i][[2]]
}
returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]])
}
--
View this message in context:
http://www.nabble.com/Loop-and-function-tf4028854.html#a11443955
Sent from the R help mailing list archive at Nabble.com.
Exactly how are you accessing it and what warnings are you getting. Your
loop is just returning a single value; the last time i=12. If you want a
vector of values back, the you have to do:
returnlow <- numeric(12)
for (i in 1:12){
gpdlow <- function(u){
p[,i]$beta -u*p[,i][[2]]
}
returnlow[i] <- gpdlow(var[,i][var[,i]<(p[,i][[2]])
}
On 7/5/07, livia <yn19832@msn.com> wrote:>
>
> Hi All, I am trying to make a loop for a function and I am using the
> following codes. "p" and "var" are some matrix obtained
before. I would
> like
> to apply the function "gpdlow" for i in 1:12 and get the
"returnlow" for
> i
> in 1:12. But when I ask for "returnlow" there are warnings and it
turns
> out
> some strange result.
>
> for (i in 1:12){
> gpdlow <- function(u){
> p[,i]$beta -u*p[,i][[2]]
> }
> returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]])
> }
>
>
> --
> View this message in context:
> http://www.nabble.com/Loop-and-function-tf4028854.html#a11443955
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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 you are trying to solve?
[[alternative HTML version deleted]]
You do not have matching parentheses in this line returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]]) most likely there is a syntax error that halts the execution of the assignment statement? --- livia <yn19832 at msn.com> wrote:> > Hi All, I am trying to make a loop for a function and I am using the > following codes. "p" and "var" are some matrix obtained before. I would > like > to apply the function "gpdlow" for i in 1:12 and get the "returnlow" for i > in 1:12. But when I ask for "returnlow" there are warnings and it turns out > some strange result. > > for (i in 1:12){ > gpdlow <- function(u){ > p[,i]$beta -u*p[,i][[2]] > } > returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]]) > } > > > -- > View this message in context: > http://www.nabble.com/Loop-and-function-tf4028854.html#a11443955 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Thanks a lot. I have corrected this. But it still does not work. Any thought? Stephen Tucker wrote:> > You do not have matching parentheses in this line > returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]]) > most likely there is a syntax error that halts the execution of the > assignment statement? > > > > --- livia <yn19832 at msn.com> wrote: > >> >> Hi All, I am trying to make a loop for a function and I am using the >> following codes. "p" and "var" are some matrix obtained before. I would >> like >> to apply the function "gpdlow" for i in 1:12 and get the "returnlow" for >> i >> in 1:12. But when I ask for "returnlow" there are warnings and it turns >> out >> some strange result. >> >> for (i in 1:12){ >> gpdlow <- function(u){ >> p[,i]$beta -u*p[,i][[2]] >> } >> returnlow <- gpdlow(var[,i][var[,i]<(p[,i][[2]]) >> } >> >> >> -- >> View this message in context: >> http://www.nabble.com/Loop-and-function-tf4028854.html#a11443955 >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at stat.math.ethz.ch 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. >> > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >-- View this message in context: http://www.nabble.com/Return-valus-for-different-numbr-of-rows-tf4028854.html#a11445807 Sent from the R help mailing list archive at Nabble.com.