Clase 1
Clase 1
Clase 1
2 + 2
9 / 3
5 %% 2
3 + 2 - 10 ^ 2
3 + (2 - 10) ^ 2
sqrt(16)
sqrt(2)
var1 <- 3
var1
var1^2
var2 = 4
var2
var2^2
var1^2 + var2^2
#funciones
cos(3.14159)
cos(pi)
acos(-1)
acos(cos(pi))
exp(1)
log(2)
log (exp(1))
log10(2)
log(16, base = 2)
factorial(10)
# indeterminados
1 / 0
0 / 0
# Operadores Lógicos
valor1 = TRUE
valor1
class(valor1)
valor2 = FALSE
valor1 || valor2
!valor1
!valor2
4 < 2
4 > 2
var1 == var2
var1 != var2
# Cadenas de texto
text1
class(text1)
toupper(text1)
substring(text1, 1, 4)
# ¿Cómo obtener la H?
paste(text1,text2)
#Vectores y llamados
vec1 <- c(8, 6, 7, 5, 3, 0, 9)
vec1
vec1[1]
vec1[7]
vec1[10]
length(vec1)
vec1[length(vec1)]
vec1[1:3]
vec1[2:5]
vec1[c(1,3,5)]
vec1+vec2
vec3
vec1+vec3
vec1+vec4
vec5
vec6
vec7
length(vec7)
vec1 + vec2
vec1 - vec2
vec1/vec2
vec1+vec8
vec1 + 3
vec1 + c(3, 3, 3, 3, 3, 3, 3)
vec1 + c(3, 3)
vec5 + c(3, 3)
vec1^2
vec1^vec2
sqrt(vec1)
exp(vec1)
log(vec1)
min(vec1)
max(vec1)
sum(vec2)
mean(vec2)
sd(vec2)
sort(vec6)
sum(vec3)
sum(vec4)
vec1 + vec4
#filtrando NA
is.na(vec4)
sum(vec8)
mean(vec8)
sum(vec1 > 5)
vec1 > 5
# Llamados II
vec4[is.na(vec4)]
vec4[!is.na(vec4)]
vec1[vec1 > 5]
vec1[vec2 > 5]
# Asignaciones
vec2[5] = 1
vec2
vec8[-2]
vec7[-(3:5)]
vec7[-c(3,5)]
vec3[4] = 2
sum(vec3)
sum(vec3)
# Matrices
m1=c(1,2,4)
m2=c(3,2,5)
m=matrix(c(m1,m2),nrow = 3,ncol=2)
m3=c(1,5,6)
m5=cbind(m,m3)
m5
m5[1:2,]
m5[,1:2]
m5[1:2,1:2]
m5[c(1,3),]
m5[,c(1,3)]
m5[c(1,3),c(1,3)]
diag(m5)
t(m)
m6 = t(m5)
m6
m4 + m5
m5 + 3
m5 %*% m6
m5 %*% m
m %*% m5
m5^2
sqrt(m5)
exp(m5)
solve(m5)
det(m5)
dim(m5)
m8 = rbind(m4,m7)
# Estructuras de control
prueba = 30
# Par e impar
ifelse(prueba %% 2 == 0, 'par','impar')
ifelse(vec1 %% 2 == 0, 'par','impar')
list = vec1
for(i in 1:length(list)){
print(list[i])
}
for(value in list){
print(value)
}
for(value in list){
print(value)
}
for(value in list){
if(value < 3){
print('perdiste')
}else{
print('pasaste')
}
}
for(value in list){
if(value > 5){
print(paste(value, " no es una nota válida"))
}
}
for(i in 1:length(list)){
if(list[i] > 5){
print(paste(value, " no es una nota válida"))
print(paste("Corregir la entrada ",i))
}
}
for(i in 1:length(list)){
if(list[i] > 5){
print(paste(list[i], " no es una nota válida y será corregida"))
list[i] = 5
}
}
list
i=1
while (i <= length(list)) {
print(list[i])
i = i+1
}
## readxl
install.packages("readxl")
library('readxl')
#setwd()
df <- read_excel("Taller1.xlsx")
colnames(df)
df["HORAS DE TRABAJO"]
df[41,"HORAS DE TRABAJO"]
df[df["HORAS DE TRABAJO"]>100]
df["HORAS DE TRABAJO"][df["HORAS DE TRABAJO"]>100]
## cargar un JSON
## JSON = javaScript Object Notation
## https://www.datos.gov.co/Transporte/SECTORES-CRITICOS-POR-EXCESO-DE-
VELOCIDAD/24ny-2dhf
install.packages("jsonlite")
library(jsonlite)
install.packages("curl")
library(curl)
dfjson <- fromJSON('https://www.datos.gov.co/resource/24ny-2dhf.json')
## Aleatorios
runif(10)
runif(10)*10
round(runif(10)*10,0)