Beginners’ guide

This is in no way an exhaustive manual, but it may help get you started. Please refer to the R documentation and manuals for more thorough information, or read “A Beginner’s Guide to R” if you can get hold of it — it’s a very user-friendly book that will greatly ease your way into the R world. Below are just a few basic instructions on using some of the functions in modTools.

1 – Get your data in a table with the variables in columns, records/observations in rows, and variables’ names in the first row. Save the table as a comma-separated values (CSV) file and name it mydata.csv.

2 – Install and open R. Copy the text of the function you want to use (provided in each blog post), paste it into the R console and press the enter key. If no error message is displayed, it means the function was correctly loaded in R. Alternatively, if the function is included in a package, it’s usually better to follow the link and install the package.

3 – Get your data into R by typing (or pasting) in the R console:

mydata <- read.csv("C:/..../mydata.csv", header = TRUE, sep = ",")

(replace what is between the straight quotes by the actual folder path to your data, keeping the straight quotes). Press enter. Bear in mind that all R commands are case-sensitive, and that the backslashes (\) commonly displayed in Windows paths must be replaced by either forward slashes (/) or double backslashes (\\).

4 – Type (or paste) the command you want to use in the R console, for example:

with(mydata, Fav(presabs = myspecies, prob = myspecies_P))

or

FDR(response = mydata[,1], predictors = mydata[ , 2:ncol(mydata)])

[presented with Pretty R]

Press the enter key. You should get the results in the R console or output window.

If you want to know what arguments to give to a function and whether they have default values defined, look at what is in the round brackets after the name of the function – for example, if you look at the multConvert function

multConvert <- function(data, conversion, cols = 1:ncol(data)) {
...

it tells you that you need to provide the name of the table containing your data, the type of conversion to apply, and (optionally) the columns to which you want to apply it – which, by default (i.e., unless otherwise stated), will be all columns from the first to the last one in the data table.

Advertisements

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s