Está en la página 1de 5

#COMANDOS E INSTRUCCIONES BÁSICAS EN R

#INGRESO DE DATOS
#VECTOR
variable=c(2,3,5,6,7,3,2,4,5,6)

datos=read.delim("clipboard",header = TRUE)

time=scan()
0.27 0.17 0.17 0.16 0.13 0.24 0.29 0.24 0.14 0.16 0.12 0.16 0.21 0.17 0.18

ORGANIZAR Y PRESENTAR DATOS


#FUNCIONES

#Tabla de frecuencias para cualitativas (tfc)


tfc<-function(variable){
fi<-table(variable)
hi<-fi/length(variable)
pi<-hi*100
atributos<-cbind(fi,hi,pi)
totales<-c(sum(fi),sum(hi),sum(pi))
par(mfrow=c(1,2))
barplot(table((variable)))
pie(table((variable)))
rbind(atributos,totales)
}

#Tabla de frecuencias para discretas (tfd)


tfd<-function(variable){
fi<-table(variable)
hi<-fi/length(variable)
pi<-hi*100
atributos<-cbind(fi,hi,pi)
totales<-c(sum(fi),sum(hi),sum(pi))
barplot(table(variable))
plot(table(variable))

Ing. Emanuel Muñoz Muñoz


emanuel.guillo@gmail.com
@emax_7
rbind(atributos,totales)
}

#Tabla de frecuencias para variables continuas (tfcont)


#calculo del ancho de clase
calW<-function(v){
r=max(v)-min(v)
k=1+3.3*log10(length(v))
k<-round(k)
w=r/k
w
}

#Tabla de frecuencia y gráfico de histograma (tfCont)


tfCont<-function(v,w){
k=1+3.3*log10(length(v))
LS<-c()
LS[1]=min(v)+w
for (i in 2:round(k))
LS[i]=LS[i-1]+w
h<-hist(v,seq(min(v),max(LS),w),plot=F)
fi<-h$counts
hi<-fi/sum(fi)
pi<-hi*100
Fi<-cumsum(fi)
Hi<-cumsum(hi)
Pi<-cumsum(pi)
hist(v,seq(min(v),max(LS),w),plot=T)
View(cbind(LS,fi,hi,pi,Fi,Hi,Pi))
}

Ing. Emanuel Muñoz Muñoz


emanuel.guillo@gmail.com
@emax_7
#MEDIDAS DE RESUMEN
#MEDIDAS DE POSICIÓN
#media
mean(variable)

#mediana
median(variable)

#frecuencia absoluta, para identificar la moda


table(variable)

#Cuantiles
quantile(variable)
q1=quantile(variable,0.25)
q2=quantile(variable,0.50)
q3=quantile(variable,0.75)

#MEDIDAS DE DISPERSIÓN
#rango
r=max(variable)-min(variable)

#Rango intercuartílico
IQR(variable)
iqr=q3-q1

#GRÁFICO DE CAJAS Y BIGOTES


boxplot(variable)
LI=q1-1.5*iqr
LS=q3+1.5*iqr

#Varianza
var(variable)

#desviación estándar
sd(variable)

#coeficiente de variación
cv=sd(variable)/mean(variable)

#MEDIDAS DE FORMA
#Asimetria
asimetria<-function(v1){

Ing. Emanuel Muñoz Muñoz


emanuel.guillo@gmail.com
@emax_7
as=3*(mean(v1)-median(v1))/sd(v1)
if(as<0){
a="ASIMETRICA NEGATIVA"
list(as,a)
}else if (as==0){
a="SIMETRICA"
list(as,a)
}else{a="ASIMETRICA POSITIVO"
list(as,a)
}
}

asimetria(variable)

#kurtosis
d9<-quantile(x,0.9)
d1<-quantile(x,0.1)

k=(0.5*(q3-q1))/(d9-d1)
k

#DATOS
ingreso<-scan()
50 140 175 270 430
50 150 180 280 450
80 150 185 285 460
80 150 190 290 500
90 150 190 295 510
90 150 195 350
90 150 250 350
95 150 250 365
130 160 250 370
140 170 250 395

time=scan()
0.27 0.17 0.17 0.16 0.13 0.24 0.29 0.24 0.14 0.16 0.12 0.16 0.21 0.17 0.18

Ing. Emanuel Muñoz Muñoz


emanuel.guillo@gmail.com
@emax_7
peso<-scan()
8 14 17 21
8 15 17 22
9 15 18 23
10 15 18 23
12 16 18 23
12 16 19 24
13 16 19 25
14 17 19 27
14 17 20
14 17 20

escolaridad<-scan()
2 9 11 12 14
4 9 11 12 14
4 9 11 12
7 9 11 12
7 9 12 12
8 9 12 12
8 9 12 13
8 9 12 13
8 9 12 14
8 10 12 14

#ENLACE DE DATOS
https://docs.google.com/viewer?a=v&pid=sites&srcid=ZGVmYXVsdGRvbWFpbnxlc3RhZ
GlzdGljYXVub2ZjYXxneDoyMmExMDBiODc4N2EyOGEx

Ing. Emanuel Muñoz Muñoz


emanuel.guillo@gmail.com
@emax_7

También podría gustarte