Evidently, I'm overlooking something simple. I'm trying to used order with data.frame. For example: t = data.frame(x = c(11,12,14), y = c(19,20,21), z = c(10,9,7)) t[order(z), ] Error in order(z) : object 'z' not found Thank you for any insights and advice provided. [[alternative HTML version deleted]]
Try: ?t[order(t$z),] #or t[with(t,order(z)),] A.K. On Sunday, March 16, 2014 12:27 AM, Jason Rupert <jasonkrupert at yahoo.com> wrote: Evidently, I'm overlooking something simple.? I'm trying to used order with data.frame. ? For example: t = data.frame(x = c(11,12,14), y = c(19,20,21), z = c(10,9,7)) t[order(z), ] Error in order(z) : object 'z' not found Thank you for any insights and advice provided. ??? [[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.
Indeed you are -- the syntax for selecting columns of a data frame (or components from a list). Advice: Read "An Introduction to R" or online tutorial of your choice to learn proper syntax. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Sat, Mar 15, 2014 at 9:21 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:> Evidently, I'm overlooking something simple. I'm trying to used order with data.frame. > > > For example: > > t = data.frame(x = c(11,12,14), y = c(19,20,21), z = c(10,9,7)) > t[order(z), ] > Error in order(z) : object 'z' not found > > Thank you for any insights and advice provided. > [[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. >
It is not order that you are having difficulty with... it is name scope. Your "z" is not a standalone variable, but a column in your "t" data frame. Try t[order(t$z), ] Note that "t" is the name of a commonly-used function in R that transposes matrices. It is generally not a good idea to reuse names like that, but it can be puzzling to avoid when you are new. I type the name of the variable I want to create alone on an interactive R console before I create it... if it tells me that variable is not defined then I proceed. You should also avoid posting HTML email to this list, as what we see is often not what you see. Read the Posting Guide for more useful advice on using the list. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On March 15, 2014 9:21:41 PM PDT, Jason Rupert <jasonkrupert at yahoo.com> wrote:>Evidently, I'm overlooking something simple.? I'm trying to used order >with data.frame. ? > > >For example: > >t = data.frame(x = c(11,12,14), y = c(19,20,21), z = c(10,9,7)) >t[order(z), ] >Error in order(z) : object 'z' not found > >Thank you for any insights and advice provided. > [[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.