Re: [R] questions on some operators in R

From: li li <hannah.hlx_at_gmail.com>
Date: Fri, 18 Jun 2010 12:01:07 -0500

Thank you all for your kind reply!

                 Hannah

2010/6/18 Greg Snow <Greg.Snow_at_imail.org>

> Just to expand a little on David's reply.
>
> The & vs. && and | vs. || issue is really about where and how you plan to
> use things. & and | work on vectors and are intended to be used to combine
> logical vectors into a new logical vector (that can be used for various
> things). && and || are used for program control, mainly in the condition of
> if or while statements. The program flow versions have the benefit of
> evaluating the left condition, then only evaluating the right condition if
> needed (this can save some warning messages and time). Compare the
> following commands:
>
> > x <- rnorm(100)
> > any(x < 0) | any(log(x) < 0)
> > any(x < 0) || any(log(x) < 0)
>
>
> The '<-' operator is for assignment, the '=' is used to match formal
> arguments in functions to their values. In some cases where it is
> unambiguous the '=' can be used in place of '<-' (see the help page). But
> you need to understand the difference since there are cases where they will
> not do the same thing.
>
> > mean( x <- rnorm(100) )
> And
> > mean( x = rnorm(100) )
>
> Do not do the same thing (well part is the same, but there is a subtle but
> significant difference).
>
> > mean( z <- rnorm(100) )
> And
> > mean( z = rnorm(100) )
>
> Are even more different.
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow_at_imail.org
> 801.408.8111
>
>
> > -----Original Message-----
> > From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-
> > project.org] On Behalf Of li li
> > Sent: Wednesday, June 16, 2010 4:33 PM
> > To: r-help
> > Subject: [R] questions on some operators in R
> >
> > Hi all,
> > I have two questions. Can some one give some help?
> >
> > The first question is regarding the pair of operators "&" and "&&".
> > What
> > is the
> > difference between the two?
> >
> > The second question is regarding "<-" and "=". Usually we use
> > "<-" as the assignment operator. I saw some people use "=". Is there
> > any difference between the two.
> >
> > Thank you!!
> > Hannah
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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-<http://www.r-project.org/posting->
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]



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 Fri 18 Jun 2010 - 17:02:49 GMT

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 Fri 18 Jun 2010 - 18:40:34 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