Understand R Speak

Understand R Speak

R as a calculator

  • R can be used like a calculator type the following into your script.  To run it when your cursor is on the line in the script press Ctrl Enter

1 + 1
  • The console will give out the answer as 2.  The square brackets is the index number of the answer. In this case the answer is only one value

> 1 + 1 [1] 2
  • R follows the rules as any calculator.  In your script calculate the following

1+1 20*5 (45*3)+3.7 2^2 pi (30/90)*100
  • The output will be as below

> 1+1 [1] 2 > 20*5 [1] 100 > (45*3)+3.7 [1] 138.7 > 2^2 [1] 4 > pi [1] 3.141593 > (30/90)*100 [1] 33.33333

R functions

  • R is made up of thousands of functions that you use to manipulate and analyse your data.   They are the equivalent to maths functions in Excel e.g. STDEV(), SUM(), MEAN()

  • A collection of themed R functions for e.g. a data type, or an analysis type is called a package

  • R has thousands and thousands of packages to integrate with propriety software (ArcGIS, Stata), other tools (Twitter, SQL) and multiple data types (.txt, .csv, .sav) including compressed file formats (e.g. NetCDF)

  • Each function has a number of arguments that are conditions for how you apply or run the function.  All R functions follow the same format:

    Function_name(arg1, arg2, arg3...)

  • R has a wonderful help file to show you exactly how to use each function and argument....it even gives examples for you to work through. 

 

Next section

The R help function