This is an R HTML document. When you click the Knit HTML button a web page 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:

setwd("/Users/kennyorielolana/Documents/DATA ANALYSIS and Mapping/Rstudio/Data")
asf_invest <- read.csv("Philippins2_Disease Invest.csv")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.5.0     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#Trial
table_1 <- asf_invest %>%
  count(Province)

table_2 <- asf_invest %>%
  group_by(Province) %>%
  filter(Result=="Positive") %>%
  count()

#join
asf_result2<- table_1 %>%
  left_join(table_2, by="Province", suffix = c("_samples", "_positive")) %>%
  replace_na(list(n_positive=0))
print(asf_result2)
##                Province n_samples n_positive
## 1                  Abra        50         23
## 2      Agusan Del Norte       202         96
## 3        Agusan Del Sur       122         86
## 4                 Aklan         3          0
## 5                 Albay        62         34
## 6                Apayao       175         97
## 7                Aurora        47         47
## 8                Bataan        86         78
## 9              Batangas       213        143
## 10              Benguet        76         37
## 11             Bukidnon         1          1
## 12              Bulacan       213        178
## 13              Cagayan       595        330
## 14      Camarines Norte        50         43
## 15        Camarines Sur       318        235
## 16             Camiguin        71         37
## 17                Capiz         2          0
## 18          Catanduanes       126        120
## 19               Cavite        62         39
## 20                 Cebu         5          1
## 21         Davao De Oro        32         31
## 22      Davao Del Norte       205        181
## 23        Davao Del Sur       204        130
## 24     Davao Occidental        76         56
## 25       Davao Oriental       124        114
## 26        Eastern Samar        51         27
## 27               Ifugao        58         54
## 28         Ilocos Norte       296        210
## 29           Ilocos Sur       213        142
## 30               Iloilo        52         37
## 31              Isabela       847        810
## 32              Kalinga        86         43
## 33             La Union       119         97
## 34               Laguna        80         61
## 35      Lanao Del Norte        58         50
## 36                Leyte       395        271
## 37           Marinduque        19          6
## 38              Masbate        15         13
## 39   Mindoro Occidental        26          3
## 40     Misamis Oriental       375        325
## 41    Mountain Province        42         27
## 42 NCR, Fourth District        11          2
## 43 NCR, Second District        36         17
## 44  NCR, Third District        23         10
## 45       North Cotabato       704        452
## 46       Northern Samar        77         35
## 47          Nueva Ecija       291        265
## 48        Nueva Vizcaya        92         71
## 49           PANGASINAN         1          1
## 50             Pampanga       242        232
## 51           Pangasinan       195        172
## 52               Quezon       495        408
## 53              Quirino       208        179
## 54                Rizal       128         87
## 55              Romblon         8          0
## 56                Samar        47         29
## 57            Sarangani        48         31
## 58             Sorsogon        20         20
## 59       South Cotabato       190         37
## 60       Southern Leyte        47         41
## 61       Sultan Kudarat       260        200
## 62    Surigao Del Norte       110         25
## 63      Surigao Del Sur       168         88
## 64               Tarlac       117         95
## 65             Zambales        33         15
## 66  Zamboanga Del Norte        32         10
## 67    Zamboanga Del Sur       104         52
## 68    Zamboanga Sibugay        52         21