# Locate the file
folder <- "/cloud/project/"
file_name <- "CornPalay.csv"
file_path <- paste0(folder, "/", file_name)
# Read the data
data <- read.csv(file_path)
# Get info from the data
dim(data)
## [1] 256 18
colnames(data)
## [1] "ARMM.Region" "CORDILLERA.REGION..CAR."
## [3] "MIMAROPA.REGION" "REGION.I..ILOCOS.REGION."
## [5] "REGION.II..CAGAYAN.VALLEY." "REGION.III..CENTRAL.LUZON."
## [7] "REGION.IV.A..CALABARZON." "REGION.IX..ZAMBO.Penin."
## [9] "REGION.V..BICOL.REGION." "REGION.VI..WEST.VISAYAS."
## [11] "REGION.VII..CENTRAL.VISAYAS." "REGION.VIII..EAST.VISAYAS."
## [13] "REGION.X..NORTHERN.MIN." "REGION.XI..DAVAO.REGION."
## [15] "REGION.XII..SOCCSKSARGEN." "REGION.XIII..CARAGA."
## [17] "Crop" "TypeCrop"
head(data)
## ARMM.Region CORDILLERA.REGION..CAR. MIMAROPA.REGION REGION.I..ILOCOS.REGION.
## 1 35615 44156 97221 185215
## 2 28117 58373 109447 68461
## 3 28316 29287 65620 82150
## 4 40024 92503 172723 517037
## 5 37811 42013 93821 196722
## 6 33857 90937 112360 72749
## REGION.II..CAGAYAN.VALLEY. REGION.III..CENTRAL.LUZON.
## 1 374342 324251
## 2 521146 606719
## 3 266236 106113
## 4 456480 675030
## 5 313519 278590
## 6 592656 652675
## REGION.IV.A..CALABARZON. REGION.IX..ZAMBO.Penin. REGION.V..BICOL.REGION.
## 1 97377 85632 107588
## 2 98076 55102 119342
## 3 36353 84677 115910
## 4 94874 76316 116043
## 5 75609 63974 108350
## 6 97448 53113 124783
## REGION.VI..WEST.VISAYAS. REGION.VII..CENTRAL.VISAYAS.
## 1 253507 32724
## 2 120417 22924
## 3 343181 20025
## 4 259667 47851
## 5 263748 37494
## 6 120581 25781
## REGION.VIII..EAST.VISAYAS. REGION.X..NORTHERN.MIN. REGION.XI..DAVAO.REGION.
## 1 98855 113282 105778
## 2 72483 113569 52556
## 3 51050 96241 67328
## 4 92031 138703 127240
## 5 105323 108920 106082
## 6 77094 142893 62949
## REGION.XII..SOCCSKSARGEN. REGION.XIII..CARAGA. Crop TypeCrop
## 1 234088 23962 Palay Irrigated
## 2 168143 81313 Palay Irrigated
## 3 308459 34426 Palay Irrigated
## 4 179248 81753 Palay Irrigated
## 5 298253 25109 Palay Irrigated
## 6 101398 92643 Palay Irrigated
tail(data)
## ARMM.Region CORDILLERA.REGION..CAR. MIMAROPA.REGION
## 251 56538 83686 16594
## 252 44756 26358 7736
## 253 43124 89726 52786
## 254 17666 31920 31693
## 255 40581 72128 17931
## 256 55940 24178 6675
## REGION.I..ILOCOS.REGION. REGION.II..CAGAYAN.VALLEY.
## 251 3336 555640.0
## 252 4058 353830.0
## 253 289127 707999.0
## 254 145734 234326.8
## 255 4256 589843.8
## 256 3624 225178.4
## REGION.III..CENTRAL.LUZON. REGION.IV.A..CALABARZON. REGION.IX..ZAMBO.Penin.
## 251 16020 8926 12462
## 252 2488 20105 7437
## 253 NA 11214 9695
## 254 NA 4956 3267
## 255 NA 4626 13224
## 256 NA 18625 8635
## REGION.V..BICOL.REGION. REGION.VI..WEST.VISAYAS.
## 251 61065 111744
## 252 42540 54493
## 253 37143 77719
## 254 60881 24769
## 255 50903 99307
## 256 39509 53087
## REGION.VII..CENTRAL.VISAYAS. REGION.VIII..EAST.VISAYAS.
## 251 730 3193
## 252 1072 3539
## 253 237 2466
## 254 77 4328
## 255 412 3066
## 256 653 3544
## REGION.X..NORTHERN.MIN. REGION.XI..DAVAO.REGION. REGION.XII..SOCCSKSARGEN.
## 251 316469.00 21713 358503
## 252 235074.00 19692 330555
## 253 201479.00 11897 203417
## 254 21891.62 5745 61232
## 255 312885.00 14256 391879
## 256 272787.00 18976 348858
## REGION.XIII..CARAGA. Crop TypeCrop
## 251 31828 Corn Yellow
## 252 341 Corn Yellow
## 253 12590 Corn Yellow
## 254 19815 Corn Yellow
## 255 29949 Corn Yellow
## 256 NA Corn Yellow
# Extract unique Crop-TypeCrop
unique_crops <- unique(data$Crop)
unique_type_crops <- unique(data$TypeCrop)
# Tabulate frequency count for each continent
table(data$Crop)
##
## Corn Palay
## 128 128
table(data$TypeCrop)
##
## Irrigated Rainfed White Yellow
## 64 64 64 64
# Use single for loop to get records for each Crop-TypeCrop
# and put the records into a list structure
crop_type_crop_list <- list()
num_crops <- length(unique_crops)
num_type_crops <- length(unique_type_crops)
# Use single for loop to get records by continent
for (i in 1:num_crops){
crop_type_crop_list[[i]] <- data[data$Crop == unique_crops[i],]
}
for (i in 1:num_type_crops){
crop_type_crop_list[[i]] <- data[data$TypeCrop == unique_type_crops[i],]
}
# Display results by structure
str(unique_crops)
## chr [1:2] "Palay" "Corn"
str(unique_type_crops)
## chr [1:4] "Irrigated" "Rainfed" "White" "Yellow"
str(crop_type_crop_list)
## List of 4
## $ :'data.frame': 64 obs. of 18 variables:
## ..$ ARMM.Region : int [1:64] 35615 28117 28316 40024 37811 33857 51104 45484 36413 34242 ...
## ..$ CORDILLERA.REGION..CAR. : int [1:64] 44156 58373 29287 92503 42013 90937 30934 121299 32969 90545 ...
## ..$ MIMAROPA.REGION : num [1:64] 97221 109447 65620 172723 93821 ...
## ..$ REGION.I..ILOCOS.REGION. : num [1:64] 185215 68461 82150 517037 196722 ...
## ..$ REGION.II..CAGAYAN.VALLEY. : num [1:64] 374342 521146 266236 456480 313519 ...
## ..$ REGION.III..CENTRAL.LUZON. : int [1:64] 324251 606719 106113 675030 278590 652675 92594 842374 325127 601783 ...
## ..$ REGION.IV.A..CALABARZON. : num [1:64] 97377 98076 36353 94874 75609 ...
## ..$ REGION.IX..ZAMBO.Penin. : int [1:64] 85632 55102 84677 76316 63974 53113 91357 78238 90041 54469 ...
## ..$ REGION.V..BICOL.REGION. : num [1:64] 107588 119342 115910 116043 108350 ...
## ..$ REGION.VI..WEST.VISAYAS. : int [1:64] 253507 120417 343181 259667 263748 120581 315073 246357 284885 120270 ...
## ..$ REGION.VII..CENTRAL.VISAYAS.: int [1:64] 32724 22924 20025 47851 37494 25781 18472 56301 40855 20013 ...
## ..$ REGION.VIII..EAST.VISAYAS. : num [1:64] 98855 72483 51050 92031 105323 ...
## ..$ REGION.X..NORTHERN.MIN. : num [1:64] 113282 113569 96241 138703 108920 ...
## ..$ REGION.XI..DAVAO.REGION. : int [1:64] 105778 52556 67328 127240 106082 62949 89182 104754 114420 59975 ...
## ..$ REGION.XII..SOCCSKSARGEN. : int [1:64] 234088 168143 308459 179248 298253 101398 335485 185396 316520 86345 ...
## ..$ REGION.XIII..CARAGA. : num [1:64] 23962 81313 34426 81753 25109 ...
## ..$ Crop : chr [1:64] "Palay" "Palay" "Palay" "Palay" ...
## ..$ TypeCrop : chr [1:64] "Irrigated" "Irrigated" "Irrigated" "Irrigated" ...
## $ :'data.frame': 64 obs. of 18 variables:
## ..$ ARMM.Region : int [1:64] 35376 21194 89361 69546 29280 24680 122324 100019 20068 37768 ...
## ..$ CORDILLERA.REGION..CAR. : int [1:64] 1194 1717 3332 25258 1209 2297 2300 23306 1043 1899 ...
## ..$ MIMAROPA.REGION : num [1:64] 54966 33213 45754 179775 55702 ...
## ..$ REGION.I..ILOCOS.REGION. : num [1:64] 719 9382 344926 1441 9706 ...
## ..$ REGION.II..CAGAYAN.VALLEY. : num [1:64] 103958 30284 3944 28747 109116 ...
## ..$ REGION.III..CENTRAL.LUZON. : int [1:64] 6352 1550 4981 235236 7507 1451 5412 293234 6380 1580 ...
## ..$ REGION.IV.A..CALABARZON. : num [1:64] 15595 5746 10544 17874 16071 ...
## ..$ REGION.IX..ZAMBO.Penin. : int [1:64] 25784 8767 69965 37355 25309 10295 63531 45263 26696 9485 ...
## ..$ REGION.V..BICOL.REGION. : num [1:64] 61279 22824 31213 98094 52736 ...
## ..$ REGION.VI..WEST.VISAYAS. : int [1:64] 164810 40140 270293 156322 182154 35520 236928 189170 216167 23823 ...
## ..$ REGION.VII..CENTRAL.VISAYAS.: int [1:64] 33280 13703 4731 39954 33449 13027 3876 36792 36682 12639 ...
## ..$ REGION.VIII..EAST.VISAYAS. : num [1:64] 81002 33324 35831 52982 86417 ...
## ..$ REGION.X..NORTHERN.MIN. : num [1:64] 3864 3535 11543 18868 3131 ...
## ..$ REGION.XI..DAVAO.REGION. : int [1:64] 6772 13249 8399 6861 6662 13475 13235 6102 8842 9190 ...
## ..$ REGION.XII..SOCCSKSARGEN. : int [1:64] 37772 18975 70701 27408 31601 7976 63609 39502 39181 6459 ...
## ..$ REGION.XIII..CARAGA. : num [1:64] 10040 41731 7264 27577 16807 ...
## ..$ Crop : chr [1:64] "Palay" "Palay" "Palay" "Palay" ...
## ..$ TypeCrop : chr [1:64] "Rainfed" "Rainfed" "Rainfed" "Rainfed" ...
## $ :'data.frame': 64 obs. of 18 variables:
## ..$ ARMM.Region : int [1:64] 111559 99735 126368 107360 125401 72099 135961 109734 75802 104515 ...
## ..$ CORDILLERA.REGION..CAR. : int [1:64] 7117 238 13858 178 7776 730 12119 85 8600 621 ...
## ..$ MIMAROPA.REGION : num [1:64] 813 1299 1157 439 570 ...
## ..$ REGION.I..ILOCOS.REGION. : num [1:64] 13080 13541 11101 2351 12469 ...
## ..$ REGION.II..CAGAYAN.VALLEY. : num [1:64] 9905 8082 29664 2665 16199 ...
## ..$ REGION.III..CENTRAL.LUZON. : int [1:64] 1805 2270 2687 148 2802 2061 3117 340 2841 2945 ...
## ..$ REGION.IV.A..CALABARZON. : num [1:64] 278 178 3189 234 308 ...
## ..$ REGION.IX..ZAMBO.Penin. : int [1:64] 18295 23823 35142 43494 18225 22867 55251 34913 15957 16505 ...
## ..$ REGION.V..BICOL.REGION. : num [1:64] 3202 1607 15949 216 3299 ...
## ..$ REGION.VI..WEST.VISAYAS. : int [1:64] 10776 4329 16707 4230 7503 4325 14811 5126 7098 4478 ...
## ..$ REGION.VII..CENTRAL.VISAYAS.: int [1:64] 16259 5878 81143 27350 15758 7521 95240 27161 22163 6656 ...
## ..$ REGION.VIII..EAST.VISAYAS. : num [1:64] 4371 16335 12885 10691 4420 ...
## ..$ REGION.X..NORTHERN.MIN. : num [1:64] 101843 38393 127257 98734 103338 ...
## ..$ REGION.XI..DAVAO.REGION. : int [1:64] 21433 26135 37131 57464 20328 23245 44346 48524 24944 27092 ...
## ..$ REGION.XII..SOCCSKSARGEN. : int [1:64] 70070 79952 81964 160282 52659 60919 111554 160657 56875 53805 ...
## ..$ REGION.XIII..CARAGA. : num [1:64] 3333 6523 22268 32575 3152 ...
## ..$ Crop : chr [1:64] "Corn" "Corn" "Corn" "Corn" ...
## ..$ TypeCrop : chr [1:64] "White" "White" "White" "White" ...
## $ :'data.frame': 64 obs. of 18 variables:
## ..$ ARMM.Region : int [1:64] 52554 52571 89887 57577 80577 47096 86097 61380 59732 61270 ...
## ..$ CORDILLERA.REGION..CAR. : int [1:64] 17248 4126 28671 979 37303 11012 22770 1757 31572 11508 ...
## ..$ MIMAROPA.REGION : num [1:64] 12804 11789 23935 4290 10804 ...
## ..$ REGION.I..ILOCOS.REGION. : num [1:64] 58548 68820 5460 545 69260 ...
## ..$ REGION.II..CAGAYAN.VALLEY. : num [1:64] 217249 245932 379183 59224 265365 ...
## ..$ REGION.III..CENTRAL.LUZON. : int [1:64] 25092 43322 1974 45114 58724 1907 62928 46977 1874 83181 ...
## ..$ REGION.IV.A..CALABARZON. : num [1:64] 4893 8669 9997 13870 5009 ...
## ..$ REGION.IX..ZAMBO.Penin. : int [1:64] 595 619 557 708 510 614 1034 895 547 487 ...
## ..$ REGION.V..BICOL.REGION. : num [1:64] 8743 14862 12855 5353 6860 ...
## ..$ REGION.VI..WEST.VISAYAS. : int [1:64] 13995 7553 19144 3606 8647 7826 22283 5019 15562 4610 ...
## ..$ REGION.VII..CENTRAL.VISAYAS.: int [1:64] 1129 328 4355 1094 1199 411 5151 1570 1185 454 ...
## ..$ REGION.VIII..EAST.VISAYAS. : num [1:64] 325 491 703 505 341 514 711 520 344 536 ...
## ..$ REGION.X..NORTHERN.MIN. : num [1:64] 93103 35103 197505 85890 67078 ...
## ..$ REGION.XI..DAVAO.REGION. : int [1:64] 887 1323 2310 4624 1974 1366 4880 3743 3618 4302 ...
## ..$ REGION.XII..SOCCSKSARGEN. : int [1:64] 106895 142059 186286 162792 82783 93330 181977 175163 93547 80686 ...
## ..$ REGION.XIII..CARAGA. : num [1:64] 114 517 3546 2083 188 ...
## ..$ Crop : chr [1:64] "Corn" "Corn" "Corn" "Corn" ...
## ..$ TypeCrop : chr [1:64] "Yellow" "Yellow" "Yellow" "Yellow" ...