Important Notice !!!

This blog has been discarded and no update any more.

Please visit http://www.quantlego.com for active updates.

Sorry for any inconvenience.





Monday, June 17, 2013

A beginner's tutorial for R

| |
  • Some common commands
  • # Quit R
    q()
    q(save="no")
     
    # Setting the default working directory
    setwd(file="c:\\AnyDirectory\\")
    setwd(file="c:/AnyDirectory/")
     
    # Get the default working directory
    getwd()
     
    # See which variables are currently in the workspace
    ls()
     
    # Remove a list of variables
    rm(var1,var2,var3,...)
     
    # Remove all objects from workspace
    rm(list=ls())
     
    # Note: the variables whose names begin with a dot are not listed by ls(), so they are not removed by above command. 
    # Instead, you can use following command to remove them
    rm(list=ls(all=TRUE))
     
    # Load a package
    library(PackageName)
     
    # Sink R output to a file
    sink(FileName)
    sink(NULL) # stop the sink

  • You can use either single- or double-quote for text
  • > cat("I said:\"Hello!\"",'then smile.')
    I said:"Hello!" then smile.
    > cat("This is Eric\'s book,",'and that is Mike\'s toy.')
    This is Eric's book, and that is Mike's toy.

0 comments:

Post a Comment

Powered by Blogger.