Suppose I have an arbitrary R object. Is there a way to find out its format? There are 118 points, each described by two numbers. Let the name of the object be "obj" without the quotes. I can do a print (obj), but all I get is a bunch of numbers. I can do a ls.str (obj), but all I get is a bunch of numbers. Is it a data frame? A vector with 118 elements, each having two sub-elements? Or ---? The object in question is of the class gam (Generalized Additive Model). I know how to pull out some data with the "predict" function, but, when I try to print the value of the predict function, all I get is a bunch of numbers. Also, how could I have looked this up without having to post a question here? Tom Thomas L. Jones, Ph.D., Computer Science
On 4/6/2006 2:24 PM, Thomas L Jones wrote:> Suppose I have an arbitrary R object. Is there a way to find out its > format? There are 118 points, each described by two numbers. Let the > name of the object be "obj" without the quotes. I can do a print > (obj), but all I get is a bunch of numbers. I can do a ls.str (obj), > but all I get is a bunch of numbers. Is it a data frame? A vector with > 118 elements, each having two sub-elements? Or ---? > > The object in question is of the class gam (Generalized Additive > Model). I know how to pull out some data with the "predict" function, > but, when I try to print the value of the predict function, all I get > is a bunch of numbers.str(obj) usually gives you the sort of thing you're looking for.> Also, how could I have looked this up without having to post a > question here?This is a tricky question. Usually RSiteSearch() will turn up useful information, but I suspect you'll get a lot of false hits if you look for "format" or "structure". Duncan Murdoch
Hi Tom, If you assume that's a common question, and so likely to be in base, help.search("object", package="base") calls up a list of functions relating to objects. (Leaving off the package argument calls up a much longer one). Browsing thru the list gets you the intriguing line: class(base) Object Classes ?class gets you more information about that function, which sounds promising. class(myobject) will tell you what class(es) myobject belongs to. names(myobject) will show you the named "subcomponents", which can be accessed with myobject$somename The object in question is of the class gam (Generalized Additive> Model). I know how to pull out some data with the "predict" function, > but, when I try to print the value of the predict function, all I get > is a bunch of numbers.I'm not sure what you mean by "value of the predict function", but you could try typing just predict.gam at the prompt to get some idea of what it's doing (although not necessarily the complete source). Sarah -- Sarah Goslee http://www.stringpage.com [[alternative HTML version deleted]]