[R] help on output my own function result in ddply

Sarah Goslee sarah.goslee at gmail.com
Fri Mar 6 05:32:18 CET 2015


 Hi,

On Thursday, March 5, 2015, JS Huang <js.huang at protective.com> wrote:

> Hi,
>
>   There is a lot of if-else statement.  r syntax rejects them.  Here is an
> example of if-else example.  In r we can code *ifelse(x>2,y <-
> 1,ifelse(x>1,y <- 0.5, y <- 0))* for the following.


I'm not sure what you are talking about: if-else is a valid construct in R,
and NOT synonymous with ifelse().

Your construct below is wrong, though, because the curly brace on a line
alne tells R that you're done. Instead you need

if(x > 2) {
   y <- 1
} else {
   y <- 0
}

and these can be nested at will. Note that else is on the same line as the
curly brace ending the if statement.

http://cran.r-project.org/doc/manuals/R-lang.html#if


>
> if (x > 2)
> {
>   y = 1
> }
> else
> {
>   if (x > 1)
>   {
>      y = 0.5
>   }
>   else
>   {
>      y = 0
>   }
> }
>
>
>
>
> -----
> JS Huang
> --
> View this message in context:
> http://r.789695.n4.nabble.com/help-on-output-my-own-function-result-in-ddply-tp4704238p4704240.html
> Sent from the R help mailing list archive at Nabble.com.


Nabble is not the R help mailing list archive, and if you don't include
context in your post the real R help list will have little idea what you're
talking about.


>
> ______________________________________________
> R-help at r-project.org <javascript:;> mailing list -- To UNSUBSCRIBE and
> more, see
> 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.
>

Instead, you could actually sign up for the mailing list.

Sarah



-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

	[[alternative HTML version deleted]]



More information about the R-help mailing list