[R] dynamic programming

From: garciap <garciap_at_usal.es>
Date: Sun, 29 May 2011 03:07:11 -0700 (PDT)


Dear members of R forum,

I'm trying to perform a simply dynamic programming model in R, following the reccomendations of Soetart & Herman (A practical guide to ecological modeling). However, I've obtained a number of problems, that I'm unable to solve (even thoughI've tried during at least 2 hours). Can anyone help me? Many thanks

> ccrit <- 0
> cmax <- 5
> cclass <- ccrit:cmax
> nc <- length(cclass)
> tmax <- 10
> times <- 1:(tmax-1)
> nprey <- 3
> dive <- c(0.02,0.1,0.14)
> pfood <- c(200,60,40)
> f <- matrix(nrow=cmax,ncol=nc ,0)
> bestpatch <- matrix(nrow=tmax-1,ncol=nc-1,0)
> V <- vector(length=nprey)
> fitness <- function(c,t)

+ {
+ cc <- pmin(c ,cmax)
+ cc <- pmax(cc,ccrit)
+ fitness <- f[t,cc-ccrit+1]
+ }

> for (t in rev(times))
+ {
+ for (c in cclass[-1])
+ {
+ V<-fitness*(c+dive*pfood, t+1)

Error: unexpected ',' in:
"{
V<-fitness*(c+dive*pfood,"
> f[t,c-ccrit] <- max(V)

Error in c - ccrit : non-numeric argument to binary operator
> bestpatch[t,c-ccrit+1] <- which.max(V)
Error in c - ccrit : non-numeric argument to binary operator
> }

Error: unexpected '}' in "}"
> }

Error: unexpected '}' in "}"
>
--
View this message in context: http://r.789695.n4.nabble.com/dynamic-programming-tp3558652p3558652.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.
Received on Sun 29 May 2011 - 11:22:46 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 29 May 2011 - 11:50:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive