Thursday 7 April 2016

Basics of R - Including how to specify path names in R

If you don't know R, or are coming back at R after a long break, the following FAQ may be a good refresh.

Is R case-sensitive?

Yes, most certainly - R is case-sensitive. However, many functions are lower case.

Example of lower case functions include getwd() and setwd("putDirectoryNameHere").

Is R interpreted or compiled?

R is an interpreted language.

How do I create a data vector in R?

Creating a data vector is one of the most fundamental operations in R.  You do so using the c() function, and assignment operator.  For example, creating a data vector of the numbers 1, 2, 3, 4 and 5 can be done using:

myVector < – c( 1, 2, 3, 4, 5)

How do I calculate correlation given two data vectors a and b?

cor(a, b)

How do I import an R script into the current session?

Use the source function.  Example: source("myScript.R").

How  do I specify pathnames in R?

Use forward slash instead of backslash for path names. Backslash is used to specify escape characters.

Can I run R "unattended"?

Yes, there is a batch mode in R, using the arguments CMD BATCH.