Last active
February 4, 2022 18:57
-
-
Save santiblanko/9521910 to your computer and use it in GitHub Desktop.
Apuntes de R (Básico)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Limpiar pantalla | |
system("clear") | |
//Definir variable | |
x <- 5 | |
//Definir vector 5 posiciones | |
x <- 5:5 | |
//asociar nombres | |
names(x) <- c("santi","mundo","lol", "asdf") | |
// Definir matriz de 5*5 | |
x <- matrix(5,5,5,5,5) | |
//Acceder a fila 1, columna 1 | |
x[1,1] | |
//funciones bacanas. | |
// -Secuencia | |
5:2 | |
seq(5,2) | |
// -Raiz cuadrada | |
sqrt(4) | |
//Definir función | |
f <- function(<arguments>) { | |
## Do something interesting | |
} | |
//Un ejemplito bacano | |
elevation <- matrix(1, 10, 10) | |
elevation[4, 6] <- 0 | |
contour(elevation) | |
persp(elevation) | |
persp(elevation, expand=0.2) | |
contour(volcano) | |
persp(volcano, expand=0.2) | |
image(volcano) | |
----------------------------------- | |
----------------------------------- | |
Media | |
limbs <- c(4, 3, 4, 3, 2, 4, 4, 4) | |
//sirve para sacar la media | |
mean(limbs) | |
//sirve para graficar limbs (No la media) | |
barplot(limbs) | |
//Aqui si le agregariamos la media | |
abline(h = mean(limbs)) | |
//Con esta otra sacaria la mediana | |
median(limbs) | |
//graficamos | |
abline(h = median(limbs)) | |
/// | |
Desviación estandar | |
pounds <- c(45000, 50000, 35000, 40000, 35000, 45000, 10000, 15000) | |
meanValue <- mean(pounds) | |
abline(h = meanValue) | |
deviation <- sd(pounds) | |
abline(h = meanValue + deviation) | |
/// | |
Agrupar por categoria | |
chests <- c('gold', 'silver', 'gems', 'gold', 'gems') | |
types <- factor(chests) | |
//si te fijas agrupo por tipo | |
print(types) | |
//me cuenta cuantos pinto por cada 1 | |
as.integer(types) | |
------------- | |
Esto ya es con 3d.. No me parece muy útil... | |
---------- | |
install.packages("rgl", repos="http://cran.at.r-project.org/") | |
plot3d(iris[,1:3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment