# para poner un CRAN mirror
install.packages("datasets", repos="http://cran.rediris.es/")
## Warning: package 'datasets' is in use and will not be installed
options(repos = c(CRAN = "https://cloud.r-project.org"))
#instalando tinytex esto porque no logro que miktex funcione de ninguna forma
library(tinytex)
#ejercicio 1
library()
install.packages("MASS")
## Installing package into 'C:/Users/orest/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## Warning: package 'MASS' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
install.packages("Survival") #es Survival o survival?
## Installing package into 'C:/Users/orest/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## Warning: package 'Survival' is not available for this version of R
##
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
## Warning: Perhaps you meant 'survival' ?
library(MASS)
library(survival)
??Rcmdr
## starting httpd help server ...
## done
# ejercicio 2
library(readr)
install.packages("readr")
## Warning: package 'readr' is in use and will not be installed
library(readr)
# help(read) esto da No documentation for ‘read’ in specified packages
data(iris)
summary(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
## Median :5.800 Median :3.000 Median :4.350 Median :1.300
## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
## Species
## setosa :50
## versicolor:50
## virginica :50
##
##
##
fivenum(iris$Sepal.Length)
## [1] 4.3 5.1 5.8 6.4 7.9
# ejercicio 3
library(MASS)
data("anorexia")
str(anorexia)
## 'data.frame': 72 obs. of 3 variables:
## $ Treat : Factor w/ 3 levels "CBT","Cont","FT": 2 2 2 2 2 2 2 2 2 2 ...
## $ Prewt : num 80.7 89.4 91.8 74 78.1 88.3 87.3 75.1 80.6 78.4 ...
## $ Postwt: num 80.2 80.1 86.4 86.3 76.1 78.1 75.1 86.7 73.5 84.6 ...
which(is.na(anorexia))
## integer(0)
which(is.null(anorexia))
## integer(0)
# anorexia$Treat[anorexia$Treat == "CBT"] <- "Cogn Beh Tr" #se podría hacer así también?
anorexia_F<- factor(anorexia$Treat,
levels=c("CBT","Cont","FT"),
labels=c("Cogn Beh Tr","Contr","Fam Tr"))
#ejercicio 4
write.csv(biopsy, "C:/Users/orest/Desktop/UOC/biopsy1.csv")
write.table(biopsy, "C:/Users/orest/Desktop/UOC/biopsy2.txt")
write_excel_csv(biopsy, "C:/Users//orest/Desktop//UOC/biopsy3.xls")
#ejercicio 5, donde esta birthwt, no esta en datasets
data(birthwt)
View(birthwt)
max(birthwt$age)
## [1] 45
min(birthwt$age)
## [1] 14
range(birthwt$age)
## [1] 14 45
birthwt$smoke[birthwt$bwt == min(birthwt$bwt)]
## [1] 1
birthwt$bwt[birthwt$age == max(birthwt$age)]
## [1] 4990
captura de pantalla para ejercicio 4
#ejercicio 6
anorexia2 <- merge(anorexia$Prewt, anorexia$Postwt)
#ejercicio 7
Identificador <-
c("I1","I2","I3","I4","I5","I6","I7","I8","I9","I10","I11","I12","I13","I14",
"I15","I16","I17","I18","I19","I20","I21","I22","I23","I24","I25")
Edad <-
c(23,24,21,22,23,25,26,24,21,22,23,25,26,24,22,21,25,26,24,21,25,27,26,22,29)
Sexo <-c(1,2,1,1,1,2,2,2,1,2,1,2,2,2,1,1,1,2,2,2,1,2,1,1,2) #1 para mujeres y 2 para hombres
Peso <-
c(76.5,81.2,79.3,59.5,67.3,78.6,67.9,100.2,97.8,56.4,65.4,67.5,87.4,99.7,87.6
,93.4,65.4,73.7,85.1,61.2,54.8,103.4,65.8,71.7,85.0)
Alt <-
c(165,154,178,165,164,175,182,165,178,165,158,183,184,164,189,167,182,179,165
,158,183,184,189,166,175) #altura en cm
Fuma <-
c("SÍ","NO","SÍ","SÍ","NO","NO","NO","SÍ","SÍ","SÍ","NO","NO","SÍ","SÍ","SÍ",
"SÍ","NO","NO","SÍ","SÍ","SÍ","NO","SÍ","NO","SÍ")
Trat_Pulmon <- data.frame(Identificador,Edad,Sexo,Peso,Alt,Fuma)
Trat_Pulmon
edad22 <- subset(Trat_Pulmon, Edad > 22)
edad22
select34 <- Trat_Pulmon[3, 4]
select34
## [1] 79.3
noalt27 <- subset(Trat_Pulmon, Edad < 27)
noalt27 <- noalt27[, -5]
#ejercicio 8
data("ChickWeight")
hist(ChickWeight$weight)
boxplot(ChickWeight$Time)
#ejercicio 9
difAnorex <- anorexia$Prewt - anorexia$Postwt
anorexia_treat_df <- data.frame(anorexia$Treat, difAnorex)
ganapeso <- subset(anorexia_treat_df, difAnorex > 0)
anorexia_treat_C_df <- subset(ganapeso, ganapeso$anorexia.Treat == "Cont")
#ejercicio 10
library(knitr)
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.