Showing posts with label R-Programming. Show all posts
Showing posts with label R-Programming. Show all posts

Sunday, October 21, 2012

Part4: Debugging in R

  Debugging tools are built with R do not part of any package. There are couple of indications that something is not right. It could be a diagnostic message something to happed.Basically three type of main indications.
  1. message: A generic notification/diagnostic message produced by the message function; execution of the function continues 
  2. warning: An indication that something is wrong but not necessarily fatal;execution of the function continues generated by the warning function 
  3. error: An indication that a fatal problem has occurred; execution stops;produced by the stop function
condition: A generic concept for indicating that something unexpected can occur; programmers can create their own conditions

So this is our basic warning,  take a log of negative number

>log(-1)
[1] NaN
Warning message:
In log(-1) : NaNs produced

Tuesday, October 9, 2012

Part3: Reading and Writing Data in R


Reading Data   

Large data objects will usually be read as values from external files rather than entered during an R session at the keyboard. R input facilities are simple and their requirements are fairly strict and even rather inflexible. If variables are to be held mainly in data frames, as we strongly suggest they should be, an entire data frame can be read directly with the read.table() function. There is also a more primitive input function, scan(), that can be called directly. There are a few principal functions reading data into R. 
  1. read.table, read.csv, for reading tabular data

    The read.table function is one of the most commonly used functions for reading data. It has a few important arguments:
    • file, the name of a file, or a connection
    • header, logical indicating if the file has a header line
    • sep, a string indicating how the columns are separated
    • colClasses, a character vector indicating the class of each column in the dataset
    • nrows, the number of rows in the dataset
    • comment.char, a character string indicating the comment character
    • skip, the number of lines to skip from the beginning
    • stringsAsFactors, should character variables be coded as factors

    For small to moderately sized datasets, you can usually call read.table without specifying any other arguments
    data <- read.table("foo.txt")

    R will automatically skip lines that begin with a # and figure out how many rows there are (and how much memory needs to be allocated). Figure what type of variable is in each column of the table. Telling R all these things directly makes R run faster and more efficiently. read.csv is identical to read.table except that the default separator is a comma.

Sunday, September 30, 2012

Part2: R-Language Basics

 Data Types and Basic Operations:

1. Objects:
   In every computer language variables provide a means of accessing the data stored in memory. R does not provide direct access to the computer’s memory but rather provides a number of specialized data structures we will refer to as objects.These objects are referred to through symbols or variables.

R has five basic or atomic classes of objects:


  1. characters
  2. numeric(real numbers)
  3. integer
  4. complex
  5. logical(True or False)
2. Basic types:

2.1 Vectors:
The most basic object in R is vector. A vector can only contain objects of the same class. But the exception is a 'list', which is represent  as a vector but can contain objects of different classes. Empty vectors can be created with the vector() function.

 2.2 Lists:
Lists are another kind of data storage. Lists have elements, each of which can contain any type of R object, i.e. the elements of a list do not have to be of the same type.

Saturday, September 29, 2012

Part1: Introduction and Installation of R Programming Language

  R is really interesting  open source programming language and software environment for statistical computing and graphics. It compiles and run on wide verity  of UNIX platforms, Windows and Mac OS. It provides, among other things, a programming language, high level graphics, interfaces to other languages and debugging facilities.

 The source code for the R software environment is written primarily in C, Fortan, and R. R is freely available under the GNU General Public License. R uses a command line interface; however, Rstudio like graphical interface are available for use with R.