R Markdown

Posted by:

What is rMarkdown?

R Markdown documents are fully reproducible. Use a productive notebook interface to weave together narrative text and code to produce elegantly formatted output. Use multiple languages including R, Python, and SQL. – rmarkdown official site

R Markdown supports dozens of static and dynamic output formats including HTML, PDF, MS Word, Beamer, HTML5 slides, Tufte-style handouts, books, dashboards, shiny applications, scientific articles, websites, and more. – rmarkdown official ...

Continue Reading →

About ggplot2 for R

Posted by:

What is ggplot2

ggplot2 is a plotting system for R, based on the grammar of graphics, which tries to take the good parts of base and lattice graphics and none of the bad parts. It takes care of many of the fiddly details that make plotting a hassle (like drawing legends) as well as providing a powerful model of graphics that makes it easy to produce complex multi-layered graphics. – http://ggplot2.org/

Web Scraping with R

Posted by:

Web table scraping

Adapted from here. more on RPubs.

theurl < - getURL("https://en.wikipedia.org/wiki/Brazil_national_football_team",.opts = list(ssl.verifypeer = FALSE) )
tables <- readHTMLTable(theurl)
tables <- list.clean(tables, fun = is.null, recursive = FALSE)
n.rows <- unlist(lapply(tables, function(t) dim(t)[1]))

NB: RCurl needed, or following messages are evoked.

Warning message: XML content does not seem to be XML: 'https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population'



theurl <- "http://en.wikipedia.org/wiki/Brazil_national_football_team"
webpage <- getURL(theurl)
webpage <- readLines(tc <- textConnection(webpage)); close(tc)

pagetree ...
Continue Reading →

R Shiny from RStudio to build interactive web application

Posted by:

Shiny is –

A web application framework for R Turn your analyses into interactive web applications No HTML, CSS, or JavaScript knowledge required.

Best place to learn is the tutorial from official site.

shiny package for R


Build a app with separate ui.R and server.R files

|-- ui.R
|-- server.R

ui.R file:


# Define UI for miles per gallon application

# ...
Continue Reading →

Grammar of Data -Data process flow with R and its three Masketeers

Posted by:

Inspired and adapted from here. dplyer tutorial here, or its own documentation. Another tutorial for dplyr and tidyr; The cheatsheet is useful too, install the dataset from the page’s footnote {php}devtools::install_github(“rstudio/EDAWR”){/php}.

magrittr: Simplifying R code with pipes

%>%, This is not a pipe.
github here, a tutorial from the author, Magrittr.

Basic piping:

x %>% f is equivalent to f(x) ...

Continue Reading →

R Basics

Posted by:

R is a free software environment for statistical computing and graphics. The following is some basics about R data types.

Comparison of vector,list,matrix and dataframe

  vector list matrix dataframe
creation c list matrix data.frame
same type Y N Y N
class class of its elements list matrix data.frame
Continue Reading →

R Source Code Blocks in Org Mode

Posted by:

Setup and configuration

Adapted from org-mode official site.

  1. Install R with binary or source code Comprehensive R Archive Network for Arch Linux, following documents here.

    sudo pacman -S r
    # and rstudio IDE
    pacaur -y rstudio-desktop-bin
  2. Install ESS (Emacs Speak Statistics) Mode

    Follow instruction here.

    (add-to-list 'load-path "~/.emacs.d/ESS/lisp")
    (require 'ess-site)
  3. Finally, you’ll need to ensure that org-babel-load-languages includes an entry for R.

Continue Reading →