[R] IF ELSE

Joshua Wiley jwiley.psych at gmail.com
Fri Jan 13 15:53:59 CET 2012


Hi jost87,

Try using a good text editor with syntax highlighting and
parenthesis/brace matching (personal preference is Emacs + ESS, others
like Rstudio, and there are tons more).  I find at least one
mismatched pair of parentheses/braces in those expressions.

Cheers,

Josh

On Fri, Jan 13, 2012 at 6:31 AM, jost87 <jost87 at hotmail.com> wrote:
> Can somebody explain the problem in the following expression?
>
> Thank you
>
>
> /> if (species == 1){
> +                   fitness <-
> (1-b)*exp(-((microsites-niche.preference)/(niche.width.specialist+a.specialist)^2)*(1-a.specialist)
> +     }else
> Error: unexpected '}' in:
> "                  fitness <-
> (1-b)*exp(-((microsites-niche.preference)/(niche.width.specialist+a.specialist)^2)*(1-a.specialist)
>    }"
>>     if (species ==2){
> +         fitness <)
> (1-b)*exp(-((microsites-niche.preference)/(niche.width.generalist+a.generalist)^2)*(1-a.generalist)
> Error: unexpected ')' in:
> "    if (species ==2){
>        fitness <)"
>>         }   else fitness <- 0
> Error: unexpected '}' in "        }"
>>     }
> Error: unexpected '}' in "    }"/
>
> --
> View this message in context: http://r.789695.n4.nabble.com/IF-ELSE-tp4292285p4292285.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.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list