Skip to content
Prev 296079 / 398506 Next

problem with ifelse

Since your code has things like this:
z<-numeric(length(t ((

either you have a serious problem with your email client or you need
to reread some introductory material and take a hard look at your
code.

Also note that g() doesn't work, because it contains the statement
return(m) but m is undefined within g().

Meanwhile, you could provide what I asked: a statement of what you
expect your code to produce given particular input. Otherwise how
would we know if we've offered the right solution, since your function
doesn't work? Using set.seed() would be a useful component of this
reproducible example.

Without having a working if poorly-written function to go by or a
clear results statement, I'm not interested in trying to rewrite your
code. But some thoughts:

Here's a new version of f().

f2 <- function(c1, c2) {
	r <- pmax(c1 + c2, c1 + 0.5)
	cbind(c1, r)
}

It looks like you expected f() to be able to take vectors, but in g()
you only return one value. Is that a mistake, or what you wanted?
Since you're also using cbind(), I assume it's a mistake.

Again, there are lots of problems here that suggest that you are
coming from some other programming language and have not taken the
time to learn much about R's syntax. This is easily remedied by
reading the introduction.

Sarah

On Wed, May 30, 2012 at 3:32 PM, Christopher Kelvin
<chris_kelvin2001 at yahoo.com> wrote:
Message-ID: <CAM_vjuksmPcsCUdbfkqi-62vFnypgKkGZBo=WRcSJ4Tb7igxsA@mail.gmail.com>
In-Reply-To: <1338406337.86106.YahooMailNeo@web65407.mail.ac4.yahoo.com>