setwd(“C:/Users/Cristian Castellanos/Desktop”)
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
data(“chickweight”) data Data<-as.data.frame(chickweight) data(ChickWeight) data str(ChickWeight) summary(ChickWeight) # Dieta 1 dieta1 <- subset(ChickWeight, Diet == 1) # Dieta 2 dieta2 <- subset(ChickWeight, Diet == 2) # Dieta 3 dieta3 <- subset(ChickWeight, Diet == 3) # Dieta 4 dieta4 <- subset(ChickWeight, Diet == 4) head(dieta1) head(dieta2) head(dieta3) head(dieta4) summary(dieta1) # Factor para dieta1 factor1 <- factor(dieta1\(Time) # Factor para dieta2 factor2 <- factor(dieta2\)Time) # Factor para dieta3 factor3 <- factor(dieta3\(Time) # Factor para dieta4 factor4 <- factor(dieta4\)Time) levels(factor1) levels(factor2) levels(factor3) levels(factor4) promedio_dieta1 <- tapply(dieta1\(weight, dieta1\)Time, mean) promedio_dieta2 <- tapply(dieta2\(weight, dieta2\)Time, mean) promedio_dieta3 <- tapply(dieta3\(weight, dieta3\)Time, mean) promedio_dieta4 <- tapply(dieta4\(weight, dieta4\)Time, mean) promedios <- unlist(list(promedio_dieta1, promedio_dieta2, promedio_dieta3, promedio_dieta4)) plot(x = unique(dieta1\(Time), y = promedio_dieta1, type = "l", col = "red",pch = 19, xlab = "Tiempo", ylab = "Pesos(gramos)", main = "Promedios de pesos diarios por dieta") lines(unique(dieta2\)Time), promedio_dieta2, col = “green”) lines(unique(dieta3\(Time), promedio_dieta3, col = "blue") lines(unique(dieta4\)Time), promedio_dieta4, col = “purple”) legend(“topright”, legend = c(“Dieta 1”, “Dieta 2”, “Dieta 3”, “Dieta 4”), col = c(“red”, “green”, “blue”, “purple”), lty = 1, cex = 0.8)