12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

object type.You can do that yourself by using the command apropos(‘print\\.’).Between the quotation marks, you can put a regular expression much like inthe grep() function we discuss in Chapter 5. In order to tell R that the dotreally means a dot, you have to precede it with two backslashes. Don’t besurprised when you get over 40 different print() functions for all kinds ofobjects.Suppose you have a data frame you want to print. R will look up the functionprint.data.frame() and use that function to print the object you passed as anargument. You also can call that function yourself like this:> small.one print.data.frame(small.one)a b1 1 22 2 1The effect of that function differs in no way from what you would get if youused the generic print(small.one) function instead. That’s because print() willgive the small.one to the print.data.frame() function to take care of it.Using default methodsIn the case of a list, you may be tempted to look for a print.list() function.But it won’t work, because the print.list() function doesn’t exist. Still that isn’t aproblem for R — R will ignore the type of the object in that case and just look for adefault method, print.default().For many generic functions, there is a default method that’s used if nospecific method can be found. If there is one, you can recognize the defaultmethod by the word default after the dot in the function name.So, if you want to print the data frame as a list, you can use the defaultmethod like this:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!