10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

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

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

Appendix E 374lines(density(x))}Then we can do these things> ourhist(x,xlab="histogram of x") # change the x label> ourhist(x,xlab="histogram of x",col="green") # changebothE.2.2 Function body and return valuesThe function body is contained in braces if there is more than one command. The bodyconsists of a collection of commands that are executed in the order given, althoughcontrol statements can change this. The last command executed is the return value of thefunction. This can be <strong>for</strong>ced by the return () function. If the return value should not printout, the invisible () function can be used <strong>for</strong> the return. This is used with many plottingfunctions.Inside a block of commands, the print () or cat () functions are used to <strong>for</strong>ce printout tothe console. Just evaluating the variable name will not <strong>for</strong>ce it to print as it does on thecommand line. In the Windows GUI, the printing may be buffered. The functionflush.console () will print any buffered output.Inside a function body, variable names are resolved by seeing if the name has beenassigned inside the body or matches a variable name. If not, then values in theenvironment in which the function was called are used. If the variable name still can’t befound an error will occur. Assignment inside a function body will not affect valuesoutside the function body unless it’s done with the

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

Saved successfully!

Ooh no, something went wrong!