\fancyhead[CO,CE]{R for Dummies}

pdftitle={R for Dummies}, pdfkeywords={R , Programming, Statistics}}

\title{R for Dummies - Review} \author{Radha Krishna} \date{today}


The purpose of this document is to document my learnings from the book,‘R for Dummies’ \\ \\ \includegraphics[width=0.4\textwidth]{figures/book_cover} \pagebreak

\textsc{March 21 , 2013} \\

It is almost 5 months since I have coded any thing in R. Partly because I have been immersed in Stochastic Processes. I thought stochastic process fundas are a long way in to the future. But thanks to Measure theory and more importantly Gallager, I am able to go over Resnick’s book. I think my path for Stochastic processes has been laid more or less. I have to walk on it daily till I master the subject. I am not too ambitious. I want to understand the subject at a slow and steady pace. In any case,let me reaffirm the path so that I don’t deviate from it.

\item An introduction to Non-Life Insurance Mathematics by Mikosch \item Adventures in Stochastic Processes \item Laplace Transformation - Schiff \item Arbitrage in Continous time \item Oksendal - SDE \item Farlow - PDE solutions \item Numerical Solutions to PDE \item Fourier Transformation \item Shreve - I \item Shreve - II \item Lawler - Stochastic processes \item Karlin I \item Karlin II \item Feller - Volume II

Even if I manage to read one book per month, it is going to take another year before I can go over the above books. I will be disciplined enough to go over the books. At the same time I want to go over Algorithms too.

I have not been programming for quite sometime and hence I am now going over this book to refresh my fundas. These little drills will ensure that R will stay in my working memory and I can use it to test code and various math fundas.

\section{Going on a Date with R }

> x <- as.Date("2012-07-27")
> x
[1] "2012-07-27"
> str(x)
 Date[1:1], format: "2012-07-27"
> weekdays(x)
[1] "Friday"
> x + 7
[1] "2012-08-03"
> x + 0:6
[1] "2012-07-27" "2012-07-28" "2012-07-29" "2012-07-30" "2012-07-31" "2012-08-01" "2012-08-02"
> startDate <- as.Date("2013-03-21")
> x <- seq(startDate, by = "3 months", length.out = 6)
> x
[1] "2013-03-21" "2013-06-21" "2013-09-21" "2013-12-21" "2014-03-21" "2014-06-21"
> months(x)
[1] "March"     "June"      "September" "December"  "March"     "June"
> quarters(x)
[1] "Q1" "Q2" "Q3" "Q4" "Q1" "Q2"
> Sys.localeconv()
    decimal_point     thousands_sep          grouping   int_curr_symbol   currency_symbol mon_decimal_point
              "."                ""                ""             "USD"               "$"               "."
mon_thousands_sep      mon_grouping     positive_sign     negative_sign   int_frac_digits       frac_digits
              ","            "03"                ""               "-"               "2"               "2"
    p_cs_precedes    p_sep_by_space     n_cs_precedes    n_sep_by_space       p_sign_posn       n_sign_posn
              "1"               "0"               "1"               "0"               "3"               "0"

R allows flexibility in terms of providing input to \texttt{as.Date}

> as.Date("21 March 2013", format = "%d %B %Y")
[1] "2013-03-21"

To specify time information in addition to dates, you can choose beteen two functions in R, \texttt{as.POSIXct()} and \texttt{as.POSIXlt()}. POSIX is the name of a set of standards that refers to the UNIX operating system. POSIXct refers to a time that is internally stored as the number of seconds since the start of 1970. POSIXlt refers to the date stored as a names list of vector for the year, month, day hours and minutes.ct refers to compact and lt refers to list.

To format a date for pretty printing, you use \texttt{format()} function which takes a POSIXct or POSIXlt datetime as input. With POSIXct , you can add and subtract seconds, With Date, you can add and subtract days. Typically it is better to convert a Date object in to POSIXlt to extract various elements of the date. Some other packages that can be explored are \item zoo \item xts \item ts \item chron \item lubridate

\section{Working in More Dimensions}