#Ernesto Perusquia #MiniProject 1 #Math 5743-999 #Professor Wayne Stewart
##Code for Mini Project 1
ddt <- read.csv("C:\\Users\\ernes\\Downloads\\DDT.csv", header = TRUE)
#This is my funciton
myddt <- function(xsp, xri){
dfsp <- ddt[ddt$SPECIES == xsp,]
dfri <- ddt[ddt$RIVER == xri,]
dfspri <- ddt[ddt$RIVER == xri & ddt$SPECIES == xsp,]
#setting boxplot popup window
options(device = "windows")
#boxplot of Lenght
boxplot(dfsp$LENGTH,
main = xsp,
ylab = "LENGTH",
col = "blue",
pch = 21,
bg = "red")
#creating a list
l <- list(dfsp=dfsp,
dfri=dfri,
dfspri=dfspri)
return(l)
#Writting datafiles out for the 3 different cases
write.csv(x = dfsp,
file = "dfsp.csv",
row.names = FALSE)
write.csv(x = dfri,
file = "dfri.csv",
row.names = FALSE,)
write.csv(x = dfspri,
file = "dfspri.csv",
row.names = FALSE)
}
#we are asked to evaluate funciton at xsp = "CCATFISH", xri = "TRM"
l <- myddt(xsp = "CCATFISH", xri = "TRM")
#Evaluating at proper asked Point
l$dfri[16,]
## RIVER MILE SPECIES LENGTH WEIGHT DDT
## 34 TRM 280 SMBUFFALO 46 1614 2.3
##Checking list Created
###Inspect the list object
head(l$dfsp)
## RIVER MILE SPECIES LENGTH WEIGHT DDT
## 1 FCM 5 CCATFISH 42.5 732 10
## 2 FCM 5 CCATFISH 44.0 795 16
## 3 FCM 5 CCATFISH 41.5 547 23
## 4 FCM 5 CCATFISH 39.0 465 21
## 5 FCM 5 CCATFISH 50.5 1252 50
## 6 FCM 5 CCATFISH 52.0 1255 150
head(l$dfri)
## RIVER MILE SPECIES LENGTH WEIGHT DDT
## 19 TRM 275 CCATFISH 48 986 8.4
## 20 TRM 275 CCATFISH 45 1023 15.0
## 21 TRM 275 CCATFISH 49 1266 25.0
## 22 TRM 275 CCATFISH 50 1086 5.6
## 23 TRM 275 CCATFISH 46 1044 4.6
## 24 TRM 275 CCATFISH 52 1770 8.2
head(l$dfspri)
## RIVER MILE SPECIES LENGTH WEIGHT DDT
## 19 TRM 275 CCATFISH 48 986 8.4
## 20 TRM 275 CCATFISH 45 1023 15.0
## 21 TRM 275 CCATFISH 49 1266 25.0
## 22 TRM 275 CCATFISH 50 1086 5.6
## 23 TRM 275 CCATFISH 46 1044 4.6
## 24 TRM 275 CCATFISH 52 1770 8.2
dir(pattern = ".csv")
## [1] "dfri.csv" "dfsp.csv" "dfspri.csv"