Professional Documents
Culture Documents
QU ES R?
R, tambin conocido como GNU S, es un lenguaje
y ambiente para computacin estadstica y grfica
(software libre).
DOCUMENTACIN SOBRE R
Los "manuales" de R, incluidos en todas las
instalaciones. Son:
An introduction to R. De lectura requerida.
Writing R extensions.
R data import/export.
The R language definition.
R installation and administration
PASOS PARA UTILIZAR R
Abrir R.
Abrir un nuevo script.
Escribir cdigo.
Seleccionar cdigo a correr.
Correr con click derecho o Ctrl+R.
FUNCIONES COMUNES
MANEJO DE DATOS
Tipos de objetos
Operadores bsicos
Generacin de secuencias
Acceso a elementos
Ordenacin
TIPOS DE OBJETOS
Vector. Coleccin ordenada de elementos
del mismo tipo.
> x <- c(1, 2, 3); y <- c("a", "b", "Hola")
> z<-c(TRUE, FALSE, TRUE)
Matriz.
> m1<-matrix(1:20, nrow=5)
> m2<-c(1:20)
> dim(m2)<-c(5,4)
Lista
> L1<-list(x,y,z)
OPERADORES BSICOS
Operaciones aritmticas
+ , - , * , / , ^, % % , % / %.
log, log10, log2, log(x, base), exp, sin, cos,
tan, sqrt
Operadores comparativos
GENERACIN DE SECUENCIAS
Sequence
seq(from = , to = , by = )
seq (from = , to = , length = )
Repeat
rep(5, times = 2)
rep(x , times= )
rep(x, each= )
ORDENACIN
Order y Sort
order(x,decreasing=TRUE)
sort(x)
PAQUETES
R consta de un "sistema base" y de paquetes
adicionales que extienden su funcionalidad.
INSTALACIN DE PAQUETES
1. Ir al men Paquetes
2. Seleccionar Instalar paquete(s)
3. Seleccionar mirror a utilizar
4. Seleccionar paquete a instalar
CMO CARGAR UN PAQUETE?
> library(nombrePaquete)
AMBIENTE GRFICO
R incluye muchas y variadas funciones para hacer
grficos.
El sistema permite desde simples plots a figuras de
calidad para incluir en artculos y libros.
FUNCIONES PARA AMBIENTE GRFICO
Plot
x <- runif(50, 0, 4)
y <- runif(50, 0, 4)
plot(x, y, main = "Ttulo principal",
+ sub = "subttulo", xlab = "x label",
+ ylab = "y label", xlim = c(-1, 5),
+ ylim = c(1, 5))
Plot.ts
Grafica series de tiempo, siguiendo la misma
estructura que la funcin plot.
Otras funciones:
o abline()
o lines()
o hist()
o boxplot()
IMPORTAR DATOS A R
Para importar datos de Excel a R se debe realizar lo
siguiente:
1. Guardar archivo de Excel como *.csv
2. En R, utilizar la siguiente funcin:
variable<-read.csv(file.choose(),header=T)
REFERENCIAS
R Core Team (2015). R: A language and environment
for statistical computing. R Foundation for
Statistical Computing, Vienna, Austria.
URL http://www.R-project.org/.