An Introduction to R Language

R language is an integrated suite for software facilities for data manipulation, calculation and graphical display.It can effectively handle data and also provide effective storage facility.R is very much a vehicle for newly developing methods of interactive data analysis. It has developed rapidly and has beeb extended by a large collection of packages.R can be regarded as an implementation of S language which was developed at Bell Laboratories by Ruck Becker, John Chambers and ALlen Wilks and also forms the basis of the S-PLUS systems.

R and Statistics

Many classical statistics and latest methodologies are available in R, bbut user always needs to prepare to do a little work to find it.As compared to other Statistical languages, R will give minimal output and store the results in a fit object for subsequent interrogation by further R functions.

Using R Interactively

in using R under UNIX the suggested procedure for the first occasion is :

Create a sub-directory, say work by running the following few commads in terminal

  > mkdir work

make this directory a working directory

  > cd work

Start the R program with the command

 > R

To quit the R program, use

 > q()

Getting help with funtions and features

For getting help simply wirte help() in R console.

  > help()

For getting help about a specific topic write help(topic_name)

  > help(solve)

For getting help about features specified by special characters

 > help("[[")

For getting help in HTML format write

 > help.start()

R commands and case sensitivity

Elementary Commands

  • These are either expressions or assignments
  • Expressions is given as a command,
    • it is evaluated,
    • Printed,
    • And the value is lost.
  • Assignments also evaluates as an expression and passes the values to a variable but the result is not automatically printed.
  • Commands are separated either by semi-colon(;) or by a newline.
  • These commands can be grouped into compound experssions by usinf braces(‘{}’)
  • Comments can be put almost everywhere by starting with a hashmark(‘#’).

Executing commands from diverting output to a file

  • if commands are stored in external file, in the working directory you can use those commands using funtion source
 > source(filename.r)
  • Window Source is also available in file menu.The function sink
  > sink("record.lis") # will store the output from console to external file
  > sink() # will restores the console once again.

Data Permanency and removing objects

Entities that are created in R are known as objects.These may be variables, arrays of numbers, character stings, functions or more general structure built from such components.During a R session, objects are created and stored by names and the R command

  > objects()
  # to display the name of the objects use
  > ls()

The collection of objects currently stored is called a workspace.

  • To remove objects the function is rm:
  > rm(object_name)

Some Common and Important Commands

For installing packages

 > install.packages("package_name") 

For updating a particular package

  update.packages("package_name") 

Getting list of previously installed packages

  > old.packages() 

Unload package

 > detach("packagename") 

Uninstall a package

 > remove.packages("packagename")

Check R Language Version

 > version()

Check working Directory for storing R files

 > getwd()

Checking Available Directories in Working directory

 > dir()

Checking of available code files in R workspace

  > ls()