Starting with R

Installation of R and R-studio in windows
  • https://cran.rediris.es/bin/windows/base/R-3.2.4revised-win.exe
  • https://download1.rstudio.org/RStudio-0.99.893.exe

Rconsole:

r.console.001

Proxy settings are configured at invocation command. I will use cygwin to start it:

 /cygdrive/c/Program\ Files/R/R-3.2.4revised/bin/x64/Rgui.exe  http_proxy=http:/localhost:8888/

You can also load values from internet explorer

 /cygdrive/c/Program\ Files/R/R-3.2.4revised/bin/x64/Rgui.exe  --internet2

Rconsole in linux

apt-get install r-recommended libxml2-dev  libcurl4-openssl-dev libssl-dev

wget https://download1.rstudio.org/rstudio-0.99.893-amd64.deb
sudo dpkg -i rstudio-0.99.893-amd64.deb

To Find which session file is freezing rstudio:

strace -f rstudio 2>&1 | grep open | grep home

Help. Sistema de ayuda

Online documentation for every package and function: http://www.rdocumentation.org/

help ("read.table")
?

Vignette the command used to open pdf help docs.

Installing new packages. Instalación de paquetes

To install new packages and dependencies

install.packages("curl", dependencies = TRUE)

To install more than one package at the same time, we can use C to make a vector of packages:

install.packages(c("curl","swirl","httr"), dependencies = TRUE)

Swirl package

Swirl()
Select_language()

Selección_001

Using and declaring variables.

myval <- 12

R simplest object  is a vector, it can be declared using c (combine)

myval <- c(12,21,2)

Variables value can be printed using print function or just their names:

print(myval) 
myval

To check the objects declared in a session

ls ()

Vectors

Defining a vector with a certain length and type

vector ("numeric", length = 23)

Create a vector with a repeating pattern

(rep(c(TRUE,FALSE),10))
 [1]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE
[20] FALSE

Using a vector to index another vector.Return positions that are multiple of 4:

my_vector[c(FALSE,FALSE,FALSE,TRUE)]

Dates. Fechas

Great tutorial to work with dates: http://www.stat.berkeley.edu/~s133/dates.html

today <- Sys.Date()

Load data from a file

mydata <- read.table("mycommaseparatedvaluefile.csv", header=TRUE, sep=",", fileEncoding = "latin1")
view (Data)

 

sdf