Tuesday, 22 March 2016

Basics of 'R' Programming

Arithmetic Operators in R
 R has the following arithmetic operators:

    Addition: +
    Subtraction: -
    Multiplication: *
    Division: /
    Exponentiation: ^
    Modulo: %%

The last two might need some explanation:

    The ^ operator raises the number to its left to the power of the number to its right: for example 3^2 is 9.
    The modulo returns the remainder of the division of the number to the left by the number on its right, for example 5 modulo 3 or 5 %% 3 is 2.









Basic data types in R

R works with numerous data types. Some of the most basic types to get started are:

    Decimals values like 4.5 are called numerics.
    Natural numbers like 4 are called integers. Integers are also numerics.
    Boolean values (TRUE or FALSE) are called logical (TRUE can be abbreviated to T and FALSE to F).
    Text (or string) values are called characters.

Note how the quotation marks on the right indicate that "some text" is a character.




Monday, 14 March 2016

Install and work in R with RStudio

RStudio is a free and open-source integrated development environment (IDE) for R, a programming language for statistical computing and graphics.It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management.

RStudio is available in two editions: RStudio Desktop, where the program is run locally as a regular desktop application; and RStudio Server, which allows accessing RStudio using a web browser while it is running on a remote Linux server. Prepackaged distributions of RStudio Desktop are available for Windows, OS X, and Linux.

RStudio is available in open source and commercial editions and runs on the desktop (Windows, OS X, and Linux) or in a browser connected to RStudio Server or RStudio Server Pro (Debian, Ubuntu, Red Hat Linux, CentOS, openSUSE and SLES).

RStudio is written in the C++ programming language and uses the Qt framework for its graphical user interface.

One can download R studio from the following website : https://www.rstudio.com/products/rstudio/

How to Install and Configure RStudio

Installing RStudio is easy. Just follow these steps:
  1. Click the Download RStudio Desktop button.
  2. Select the installation file for your system.
  3. Run the installation file.
RStudio will be installed on your system. It normally detects your latest installed R version automatically. If you didn’t do anything funky, you should be able to use R from within RStudio without extra configuration.

How to configure RStudio

You may want to use a different R version from the one RStudio detected. For example, you may want to use R in a 64-bit context. Or RStudio may not have recognized your installation of R. In that case, you can set which R version to use by choosing Tools→Options to open the Options pane.
image0.jpg To change the R version, click the Change button. Then you can switch between the default 32-bit R installation or the 64-bit R installation (if installed), or you can choose a specific version of R. (RStudio lists all the versions it can find.)
If you click Browse, you can select the root directory for any R version you want to use. This folder normally looks something like …/R/R-n.n.n. If you select an R version that has both 32-bit and 64-bit builds, RStudio will ask you which build you want to use.
In the Options pane, you also can tweak the behavior of R in RStudio. If you click the General icon in the left column, you get all the default options for R in RStudio:
  • Initial working directory: You can set the default working directory R will use at startup.
  • Save workspace to .RData on exit: Your options are Ask, Never, or Always. By default, RStudio asks you whether you want to save the workspace when you quit.
  • Restore .RData into workspace at startup: Select this check box to let RStudio restore the workspace automatically at startup. RStudio will look for a saved workspace in the root folder or the default working directory.
  • Always save history (even when not saving .RData): Select this check box to have RStudio always save the history. If you don’t select this check box, RStudio doesn’t save the history when you exit the program.
  • Use single global history (rather than per-working directory): Select this check box to have RStudio always save the history in a single global file.
  • Remove duplicate entries in history: If you select this check box, RStudio removes duplicate entries from your history when the history is saved.
  • Comprehensive R Archive Network (CRAN) mirror: Click the Change button to set the CRAN mirror site that RStudio uses to install new packages.
These settings work for R only from within RStudio. If you use R with another editor or by itself, the settings in RStudio will have no effect.

 


Friday, 25 December 2015

What is R (programming language)

R is a programming language and software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing. The R language is widely used among statisticians and data miners for developing statistical software and data analysis. Polls, surveys of data miners, and studies of scholarly literature databases show that R's popularity has increased substantially in recent years.

R is a GNU project. The source code for the R software environment is written primarily in C, Fortran, and R. R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating systems. While R has a command line interface, there are several graphical front-ends available.

R is an interpreted language; users typically access it through a command-line interpreter.

Interfaces

Graphical user interfaces

  • Architect – cross-platform open source IDE for data science based on Eclipse and StatET
  • DataJoy  – Online R Editor focused on beginners to data science and collaboration.
  • Deducer – GUI for menu-driven data analysis (similar to SPSS/JMP/Minitab).
  • Java GUI for R – cross-platform stand-alone R terminal and editor based on Java (also known as JGR).
  • Number Analytics - GUI for R based business analytics (similar to SPSS) working on the cloud.
  • Rattle GUI – cross-platform GUI based on RGtk2 and specifically designed for data mining.
  • R Commander – cross-platform menu-driven GUI based on tcltk (several plug-ins to Rcmdr are also available).
  • Revolution R Productivity Environment (RPE) – Revolution Analytics-provided Visual Studio-based IDE, and has plans for web based point and click interface.
  • RGUI – comes with the pre-compiled version of R for Microsoft Windows.
  • RKWard – extensible GUI and IDE for R.
  • RStudio – cross-platform open source IDE (which can also be run on a remote Linux server).
There is a special issue of the Journal of Statistical Software that discusses GUIs for R.

Editors and IDEs

Text editors and Integrated development environments (IDEs) with some support for R include: ConTEXTEclipse (StatET), Emacs (Emacs Speaks Statistics), LyX (modules for knitr and Sweave), VimjEditKate, Revolution R Enterprise DevelopR (part of Revolution R Enterprise), RStudioSublime TextTextMateAtomWinEdt (R Package RWinEdt), Tinn-R, Notepad++, and Architect.

Scripting languages

R functionality has been made accessible from several scripting languages such as PythonPerlRubyF# and Julia.Scripting in R itself is possible via a front-end called littler.