1
set.seed(123)
rto = sort(rnorm(100, 3, 0.3))
ge = sort(runif(100, 1.01, 1.15), decreasing = T)
eje1 <- function(rto,ge){
cor_rto_ge_5 = c()
dim_rto = length(rto)
dim_ge = length(ge)
x = c()
if (dim_ge == dim_rto){
for (i in 1:(dim_ge/5)){
x = c(x,i);
cor_rto_ge_5 = c(cor_rto_ge_5,cor(ge[((5*i)-4):(5*i)],rto[((5*i)-4):(5*i)]))
}
plot(x,cor_rto_ge_5,'o')
return(cor_rto_ge_5)
}else{
print('Los vectores deben ser del mismo tamaño')
}
}
eje1(rto,ge)
## [1] -0.9777246 -0.9826204 -0.7817105 -0.8154947 -0.9938266 -0.8986719
## [7] -0.8891347 -0.9419124 -0.8400340 -0.9468725 -0.8781221 -0.9075795
## [13] -0.9915715 -0.9583870 -0.9954072 -0.8366673 -0.8103400 -0.9232177
## [19] -0.9576999 -0.8677534
2
set.seed(123)
precio = rnorm(50, 2500, 300)
eje2 <- function(n){
y = c()
x = c()
for (i in 1:length(n)){
x = c(x,i);
y = c(y,mean(n[-i]))
}
plot(x,y,type = 'o')
return(y)
}
eje2(n = precio)
## [1] 2513.963 2511.941 2500.989 2510.100 2509.740 2500.031 2507.710 2518.277
## [9] 2514.737 2513.260 2503.037 2508.329 2508.078 2509.854 2513.935 2499.591
## [17] 2507.484 2522.572 2506.238 2513.426 2517.069 2511.866 2516.813 2514.994
## [25] 2514.358 2520.858 2505.402 2509.593 2517.500 2502.855 2507.921 2512.338
## [33] 2505.051 2505.155 2505.502 2506.316 2507.140 2510.911 2512.405 2512.861
## [41] 2514.785 2511.805 2518.279 2497.252 2503.136 2517.408 2512.998 2513.389
## [49] 2505.756 2511.042
3
eje3 <- function(n){
#eje3 <- function(n,m,p){
muestra = c()
x = c()
for (i in 1:200) {
#for (i in 1:m){
x = c(x,i);
muestra = c(muestra,mean(sample(n,5)))
#muestra = c(muestra,mean(sample(n,p)))
}
plot(x,muestra,'o')
desv = sd(muestra)
return(desv)
}
eje3(n = precio)
## [1] 114.0873