I can code summary(midterm_df$hv109) and I get the summary of variable hv109. No problem. Yet when I write the code: summary(hv109, data = midterm_df) I get this error: Error in h(simpleError(msg, call)) : error in evaluating the argument 'object' in selecting a method for function 'summary': object 'hv109' not found If I write the code summary('hv109', data = midterm_df), R treats hv109 as if it were a character variable. It is not. Page 521 in Andrews *Doing Data Science in R* shows the data = [df] command. I thought it was straightforward. Why doesn't my code work? Any help w/ this would be appreciated. -- Jerome Anderson [[alternative HTML version deleted]]
Hi, As far as I can tell, I don't think the function 'summary()' will accept the 'data=' argument: see help(summary). Probably the reference you're mentionning (Andrews *Doing Data Science in R*) is about another function but not summary(). Olivier. On Fri, 3 Oct 2025 19:54:42 -0400 R Jerome Anderson <rjerome.anderson at gmail.com> wrote:> I can code summary(midterm_df$hv109) and I get the summary of variable > hv109. No problem. > > Yet when I write the code: > > summary(hv109, data = midterm_df) > > I get this error: > > Error in h(simpleError(msg, call)) : error in evaluating the argument > 'object' in selecting a method for function 'summary': object 'hv109' > not found > > If I write the code summary('hv109', data = midterm_df), R treats > hv109 as if it were a character variable. It is not. > > Page 521 in Andrews *Doing Data Science in R* shows the data = [df] > command. I thought it was straightforward. Why doesn't my code work? > > Any help w/ this would be appreciated. > > -- Jerome Anderson > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 > https://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code.-- Olivier Crouzet, PhD http://olivier.ghostinthemachine.space /Ma?tre de Conf?rences/ @LLING - Laboratoire de Linguistique de Nantes UMR6310 CNRS / Universit? de Nantes
Oups, I think the answer is more complex than my previous one. summary() is a method that will apply differently depending on the object it's applied to. So it may not behave similarly depending on whether it's applied on a model-fitting object or on a data frame. You're trying to apply it on a data frame and the 'data=' argument is not part of the summary's data frame method (which conforms to my previous answer), though it may be available for model fitting objects (which may be how Andrews uses it in the referenced book). Olivier. On Fri, 3 Oct 2025 19:54:42 -0400 R Jerome Anderson <rjerome.anderson at gmail.com> wrote:> I can code summary(midterm_df$hv109) and I get the summary of variable > hv109. No problem. > > Yet when I write the code: > > summary(hv109, data = midterm_df) > > I get this error: > > Error in h(simpleError(msg, call)) : error in evaluating the argument > 'object' in selecting a method for function 'summary': object 'hv109' > not found > > If I write the code summary('hv109', data = midterm_df), R treats > hv109 as if it were a character variable. It is not. > > Page 521 in Andrews *Doing Data Science in R* shows the data = [df] > command. I thought it was straightforward. Why doesn't my code work? > > Any help w/ this would be appreciated. > > -- Jerome Anderson > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 > https://www.R-project.org/posting-guide.html and provide commented, > minimal, self-contained, reproducible code.-- Olivier Crouzet, PhD http://olivier.ghostinthemachine.space /Ma?tre de Conf?rences/ @LLING - Laboratoire de Linguistique de Nantes UMR6310 CNRS / Universit? de Nantes
You desperately need to study your reference material more carefully or talk to your instructor... h109 is clearly something part of midterm_df and not an object on its own in your working environment. Also, read the help for sample.default and sample.lm... they work with different arguments when the first argument is a different kind of object. I don't expect the latter point to be obvious at first, but I am also not really supposed go into more detail... do please read the Posting Guide mentioned at the bottom of every message on this email list... there is a warning that this list does not permit answering homework because there is no way for us invisible remote people to know what the ground rules are for an educational institution or an educator who is being paid to educate and is responsible for doing so. On October 3, 2025 4:54:42 PM PDT, R Jerome Anderson <rjerome.anderson at gmail.com> wrote:>I can code summary(midterm_df$hv109) and I get the summary of variable >hv109. No problem. > >Yet when I write the code: > >summary(hv109, data = midterm_df) > >I get this error: > >Error in h(simpleError(msg, call)) : error in evaluating the argument >'object' in selecting a method for function 'summary': object 'hv109' not >found > >If I write the code summary('hv109', data = midterm_df), R treats hv109 as >if it were a character variable. It is not. > >Page 521 in Andrews *Doing Data Science in R* shows the data = [df] >command. I thought it was straightforward. Why doesn't my code work? > >Any help w/ this would be appreciated. > >-- Jerome Anderson > > [[alternative HTML version deleted]] > >______________________________________________ >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 https://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.-- Sent from my phone. Please excuse my brevity.
On 10/4/2025 12:54 AM, R Jerome Anderson wrote:> I can code summary(midterm_df$hv109) and I get the summary of variable > hv109. No problem. > > Yet when I write the code: > > summary(hv109, data = midterm_df) > > I get this error: > > Error in h(simpleError(msg, call)) : error in evaluating the argument > 'object' in selecting a method for function 'summary': object 'hv109' not > found > > If I write the code summary('hv109', data = midterm_df), R treats hv109 as > if it were a character variable. It is not. > > Page 521 in Andrews *Doing Data Science in R* shows the data = [df] > command. I thought it was straightforward. Why doesn't my code work? > > Any help w/ this would be appreciated. > > -- Jerome Anderson > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 https://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.Hello, ?summary has no argument 'data'. You must use the first form. Hope this helps, Rui Barradas
On 2025-10-03 7:54 p.m., R Jerome Anderson wrote:> I can code summary(midterm_df$hv109) and I get the summary of variable > hv109. No problem. > > Yet when I write the code: > > summary(hv109, data = midterm_df) > > I get this error: > > Error in h(simpleError(msg, call)) : error in evaluating the argument > 'object' in selecting a method for function 'summary': object 'hv109' not > found > > If I write the code summary('hv109', data = midterm_df), R treats hv109 as > if it were a character variable. It is not. > > Page 521 in Andrews *Doing Data Science in R* shows the data = [df] > command. I thought it was straightforward. Why doesn't my code work? > > Any help w/ this would be appreciated.Not all functions support a `data` argument. You can read about the `summary()` function using `?summary`, and none of the variations shown there have `data` as an argument. For cases like this, you can use the `with()` function, e.g. with(midterm_df, summary(hv109)) `with()` temporarily attaches the columns of the dataframe as separate variables. Duncan Murdoch