load libraries
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
import catfish data
catfishdata = read.csv("CatfishFarm.csv",header = TRUE)
catfishdata = catfishdata[-8:-9,]
colnames(catfishdata) = unlist(catfishdata[1,])
catfishdata = catfishdata[-1,]
Rename the columns
colnames(longformatcatfishdata) = c('Year','Broodfish','Fingerling','Large Size','Medium Size','Small Size','Stockers')
Convert to dataframe, convert to numeric columns, and calculate row totals for analysis.
catfishdf = data.frame(longformatcatfishdata)
catfishdf$Broodfish = as.numeric(gsub(",","",catfishdf$Broodfish))
catfishdf$Fingerling = as.numeric(gsub(",","",catfishdf$Fingerling))
catfishdf$Large.Size = as.numeric(gsub(",","",catfishdf$Large.Size))
catfishdf$Medium.Size = as.numeric(gsub(",","",catfishdf$Medium.Size))
catfishdf$Small.Size = as.numeric(gsub(",","",catfishdf$Small.Size))
catfishdf$Stockers = as.numeric(gsub(",","",catfishdf$Stockers))
catfishdf$Total = rowSums(catfishdf[,2:7])
Calculation of Average Annual Growth Rate
averageannualgrowthrate = (((catfishdf$Total[nrow(catfishdf)]-catfishdf$Total[1])/catfishdf$Total[1])*100)/(as.numeric(catfishdf$Year[nrow(catfishdf)])-as.numeric(catfishdf$Year[1]))
Calculation of YoY change of Total Population
yoy_change = list()
for(i in 1:nrow(catfishdf)){
a = ifelse(i == 1,0,(((catfishdf$Total[i]-catfishdf$Total[i-1])/catfishdf$Total[i-1])*100))
yoy_change[i] = a
}
Appending of New columns to the final data frame.
catfishdf$YoY_Change = yoy_change
catfishdf$Cooking_Style = 'Fried'
Conclusion: The average annual growth rate is -2.52%, indicating that the overall catfish population was on a steady decline year over year. The YoY change indicates there were only small periods of actual growth.
print(paste("The average annual growth rate is ",round(averageannualgrowthrate,2),"%",sep = ""))
## [1] "The average annual growth rate is -2.52%"
print(catfishdf)
## Year Broodfish Fingerling Large.Size Medium.Size Small.Size Stockers
## 1 1992 1491 849412 6769 70495 166731 634353
## 2 1993 1169 669491 6698 61894 153600 571254
## 3 1994 1183 648628 5196 48851 134314 548207
## 4 1995 1301 724693 4536 59159 138160 554342
## 5 1996 1171 823397 6644 64858 156297 627834
## 6 1997 1163 873457 7810 84725 178448 754816
## 7 1998 1187 975542 7295 62140 178511 607878
## 8 1999 1155 986368 9266 63049 182251 678682
## 9 2000 1377 1053300 5812 77149 200032 790683
## 10 2001 1327 1023533 6872 87926 239655 845287
## 11 2002 1171 1066400 10746 106117 287591 676378
## 12 2003 1303 990163 11195 127908 254920 775226
## 13 2004 1113 745849 10947 109120 261323 890275
## 14 2005 1053 712144 10642 95240 243090 660000
## 15 2006 1091 1045266 10823 103591 214848 781958
## 16 2007 886 985620 8986 104080 210340 586320
## 17 2008 801 951910 9290 107800 204750 688844
## 18 2009 704 728340 9316 105610 193870 586069
## 19 2010 536 429590 8570 91790 169030 366090
## 20 2011 495 568990 6212 54130 115560 380660
## 21 2012 562 451100 3595 64740 112970 463485
## 22 2013 540 398510 5155 58015 103520 339260
## 23 2014 650 420060 4500 50600 102190 289080
## 24 2015 577 449510 5090 48220 96810 248790
## 25 2016 520 328570 3520 45775 100850 204800
## Total YoY_Change Cooking_Style
## 1 1729251 0 Fried
## 2 1464106 -15.33294 Fried
## 3 1386379 -5.308837 Fried
## 4 1482191 6.910953 Fried
## 5 1680201 13.35928 Fried
## 6 1900419 13.10665 Fried
## 7 1832553 -3.571107 Fried
## 8 1920771 4.81394 Fried
## 9 2128353 10.80722 Fried
## 10 2204600 3.582441 Fried
## 11 2148403 -2.549079 Fried
## 12 2160715 0.5730768 Fried
## 13 2018627 -6.575971 Fried
## 14 1722169 -14.68612 Fried
## 15 2157577 25.28254 Fried
## 16 1896232 -12.11289 Fried
## 17 1963395 3.541919 Fried
## 18 1623909 -17.29076 Fried
## 19 1065606 -34.38019 Fried
## 20 1126047 5.671984 Fried
## 21 1096452 -2.628221 Fried
## 22 905000 -17.46105 Fried
## 23 867080 -4.190055 Fried
## 24 848997 -2.085505 Fried
## 25 684035 -19.43022 Fried