toolkit

 

R Examples For Actuaries - Some Preliminaries

Page history last edited by Anonymous 3 yrs ago

An Introduction to R: Examples for Actuaries

 

Nigel De Silva (nigel.desilva@thomasmiller.com)


Up to: Contents

Back to: Introduction

Forward to: R Data Structures


2.1 Starting R in Windows

 

Please refer to the R Project website for instructions on installing R and any add-on packages.

 

There are several ways to input commands to R. Firstly, there is the command window. This is available immediately after starting R and it contains the command line prompt “>”, which is an invitation to start typing. For example, if we enter:

> 2 + 2 
[1] 4 
>

 

we obtain the answer 4! The [1] indicates that the first element of the response follows. The last “>” indicates that R is ready for another command.


Secondly, there is the script window. This is a simple text editor with which to write and save more complex commands of series of commands. It can be accessed from the File menu item. You can create a new script or open an existing one. In this window, we can type a number of commands or an entire program.


To execute the commands, highlight them and click on the “Run line or selection” icon in the middle of the script file editor toolbar. The commands are automatically copied over to the command window and run.


 

2.2 Getting help with functions and features

 

To get information on any specific named function, for example plot, the command is

 

  > help(plot) 

 

An alternative is

 

  > ?plot 

 

For a feature specified by special characters, the argument must be enclosed in double or single quotes, making it a “character string”: This is also necessary for a few words with syntactic meaning including if, for and function.

 

  > help("[[") 

 

Help is available in HTML format by running or via the

 

  > help.start() 

 

which will launch a Web browser that allows the help pages to be browsed with hyperlinks. The `Search Engine and Keywords' link in the page loaded by help.start is particularly useful as it is contains a high-level concept list which searches though available functions. It can be a great way to get your bearings quickly and to understand the breadth of what R has to offer.

 

The examples on a help topic can normally be run by

 

  > example(topic) 

 

The examples in this series will not discuss all functions used in the examples. Neither will it discuss all of the options available for each function. Use the help functions, detailed above, to get further information as necessary.

Comments (2)

trevor maynard said

at 4:13 pm on Jun 9, 2006

Regarding 2.1 you could also mention TinnR as an alternative to the script window

Nigel De Silva said

at 8:15 pm on Jun 11, 2006

Good idea! Will update this after the paper.

You don't have permission to comment on this page.