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.

Using internal functionsWriting your functions in such a way that they need objects in the globalenvironment doesn’t really make sense, because you use functions to avoiddependency on objects in the global environment in the first place.In fact, the whole concept behind R strongly opposes using global variablesused in different functions. As a functional programming language, one of the mainideas of R is that the outcome of a function should not be dependent on anythingbut the values for the arguments of that function. If you give the arguments thesame values, you always get the same result. If you come from other programminglanguages like Java, this characteristic may strike you as odd, but it has its merits.Sometimes you need to repeat some calculations a few times within a function, butthese calculations only make sense inside that function.Suppose you want to compare the light production of some lamps at halfpower and full power. The towels you put in front of the window to block the sunout aren’t really up to the job, so you also measure how much light is still comingthrough. You want to subtract the mean of this value from the results in order tocorrect your measurements.To calculate the efficiency at 50 percent power, you can use the followingfunction:calculate.eff

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

Saved successfully!

Ooh no, something went wrong!