[R] with and evaluation

Jim Lemon drjimlemon at gmail.com
Fri Sep 9 04:03:52 CEST 2016

Hi Carl,
order vs sort
The order function just returns the indices necessary to put the
object into the sorted order, while the sort function returns the
sorted object. If you want to use the order function:


Yes, "with" can be a bit challenging. Think of it as:

with(take_this_thing, and_do_this_with_it)

The usual problem is working out what you want to do and what you want
the function to return. It's probably best to just do things to data
objects in a stepwise manner until you get used to that.


On Fri, Sep 9, 2016 at 9:07 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
> On 08/09/2016 6:57 PM, Carl Sutton via R-help wrote:
>> Hi
>> I have doing the R-exercises to improve my R programming capabilities.
>> Data.frame exercise 4 showed me that I have  a language problem.  Here's the
>> problem and my "solution".
>> #  Exercise 4#  Create a simple data frame from 3 vectors. Order the
>> entire data frame by the#  first column.df2 <- data.frame(a = 5:1,b =
>> letters[1:5], c = runif(5))order(df2$a) Naturally the order function did
>> nothing.
>> Per "help"Description
>> order returns a permutation which rearranges its first argument into
>> ascending or descending order, breaking ties by further arguments. sort.list
>> is the same, using only one argument.See the examples for how to use these
>> functions to sort data frames, etc.
>> Usage
>> order(..., na.last = TRUE, decreasing = FALSE,      method = c("shell",
>> "radix"))
>> sort.list(x, partial = NULL, na.last = TRUE, decreasing = FALSE,
>> method = c("shell", "quick", "radix"))Arguments
>> ... a sequence of numeric, complex, character or logical vectors, all of
>> the same length, or a classed R object.
>> Well, doesn't ... mean any legal object?  I gave it a legal object and got
>> nada.And the answer absolutely has me screaming "Say
>> What"df2[with(df2,order(a)),]
>> What's with "with?  It is one function I do not use because I find it
>> incomprehensible.  To witEvaluate an R expression in an environment
>> constructed from data, possibly modifying (a copy of) the original data.
>> First of all, if I'm not modifying data (or as a subset activity creating
>> data), why an I doing whatever it is I'm doing? ("possibly modifying (a copy
>> of) the original data.")
>> Evaluate.  According to the thesarus A) assess(v), b) appraise, c) gage.
>> OK, am I in a safe area?  I'll evaluate that.  Do I desire future social
>> contact with this person?  I'll evaluate that.In no way do I ever evaluate
>> an equation.  I may attempt to solve it.  I may do a computer program to do
>> the calculations and return a result.  I will probably evaluate the result
>> as to whether or not it helps solve the problem.  Think in terms of an
>> income tax return.  But evaluate an R expression?  No clue what that might
>> mean.
>> The remainder of the definition is also obtuse.  an R expression in an
>> environment constructed from data.  Why would one make an environment
>> without data?  Obviously I am missing the point.  My own created function
>> makes a new environment, but I only created it to crunch numbers.  If it
>> doesn't crunch numbers it's useless.
>> The point is, I do not understand the definition of "with" and thus have
>> no idea how to use it.  I guess computerese is analogous to taxlawese.
>> Familiar words have entirely different meanings.
>> Carl Sutton CPA
>>         [[alternative HTML version deleted]]
> This is really hard to read, because you posted in HTML.  If you don't get a
> useful answer, please try again in plain text.
> Duncan Murdoch
> ______________________________________________
> R-help at r-project.org 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.

More information about the R-help mailing list