100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
STAT 404 - MIDTERM 2 Terms in this set (44) Why do we need functions? Data structures tie related values into one object Functions tie related commands into one object In both cases: easier to understand, easier to work with, easier to build int €5,64   In winkelwagen

Tentamen (uitwerkingen)

STAT 404 - MIDTERM 2 Terms in this set (44) Why do we need functions? Data structures tie related values into one object Functions tie related commands into one object In both cases: easier to understand, easier to work with, easier to build int

 6 keer bekeken  0 keer verkocht
  • Vak
  • CGFO - Certified Government Finance Officer
  • Instelling
  • CGFO - Certified Government Finance Officer

STAT 404 - MIDTERM 2 Terms in this set (44) Why do we need functions? Data structures tie related values into one object Functions tie related commands into one object In both cases: easier to understand, easier to work with, easier to build into larger things Function struc...

[Meer zien]

Voorbeeld 2 van de 9  pagina's

  • 3 augustus 2024
  • 9
  • 2024/2025
  • Tentamen (uitwerkingen)
  • Vragen en antwoorden
  • CGFO - Certified Government Finance Officer
  • CGFO - Certified Government Finance Officer
avatar-seller
8/3/24, 2:01 PM



STAT 404 - MIDTERM 2
Jeremiah


ama




Terms in this set (44)

Data structures tie related values into one object


Functions tie related commands into one object
Why do we need functions?

In both cases: easier to understand, easier to work with, easier to build into larger
things

The structure of a function has three basic parts:
Function structure
- Name Inputs (or arguments): what should a user provide to the function?
- Arguments
- Body Body: code that is executed
- Return
Output (or return value): what is the side effect of your function

Things you're going to re-run, especially if it will be re-run with changes to arguments


What should be a function? Chunks of code which are small parts of bigger analyses


Chunks of code which are very similar to other chunks1

Test code outside a function first


Put code in a function and test


Best practices when creating a function Replace hard coded values with arguments and test again


Use parenthesis liberally


Only include in the function what can be repeate

With no explicit return() statement, the default is just to return whatever is on the last
What is the default return value?
line

A function can also specify default values for the inputs (if the user doesn't specify an
How and when to use default inputs
input in the function call, then the default value is used)




1/9

, 8/3/24, 2:01 PM
Inputs can be called by name, or without


Calling functions we define works just like Inputs can be called by partial names (if uniquely
calling built-in functions: named arguments,
default. When inputs aren't specified, default values are


Named inputs can go in any order

While named inputs can go in any order, unnamed inputs must go in the proper order
(as they are specified in the function's definition).
How are argument values matched to
arguments when a function is called?
When calling a function with multiple arguments, use input names for safety, unless
you're absolutely certain of the right order for (some) inputs10

When creating a function in R, though you cannot return more than one output, you
How to return more than one output
can return a list. This (by definition) can contain an arbitrary number of arbitrary objects

A side effect of a function is something that happens as a result of the function's body,
but is not returned.Examples:


Printing something out to the console
What is a side effect?

Plotting something on the display


Saving an R data file, or a PDF, etc.

Interfaces mark out a controlled inner environment for our code


Interact with the rest of the system only at the interface
Interfaces control what the function can see
(arguments, environment) and change (its Advice: arguments explicitly give the function all the information
internals, its return value) - Reduces risk of confusion and error
- Exception: true universals like π


Likewise, output should only be through the return value

In R, functions are objects, just like everything else

What do we mean by functions are objects?
This means that they can be passed to functions as arguments and returned by
functions as outputs as well

Beyond regular functions, we can use


Functionals: functions that take another function as
an argument (like the apply family). Most likely to
use
What are the four higher order classifications
of functions?
Function factories: functions that create functions
(like ecdf()). Less common.


Function operators: functions that take functions as
input and output a function




2/9

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

Verzekerd van kwaliteit door reviews

Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper Denyss. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €5,64. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 78861 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€5,64
  • (0)
  Kopen