Skip to content

Instantly share code, notes, and snippets.

@avallecam
Last active October 4, 2023 19:33
Show Gist options
  • Save avallecam/48f458da49135feceb9b86bc97143f2c to your computer and use it in GitHub Desktop.
Save avallecam/48f458da49135feceb9b86bc97143f2c to your computer and use it in GitHub Desktop.
collect some examples of rowwise relevant (?) data
``` r
# from dplyr --------------------------------------------------------------
# https://dplyr.tidyverse.org/articles/rowwise.html#creating
library(tidyverse)
df <- tibble(
x = 1:2,
y = 3:4,
z = 5:6
)
df
#> # A tibble: 2 × 3
#> x y z
#> <int> <int> <int>
#> 1 1 3 5
#> 2 2 4 6
# from experience ---------------------------------------------------------
#
# - hospital admissions
# - multiple weeks
# - multiple regions
#
# from tidyr --------------------------------------------------------------
# total number of constructions across regions per month
tidyr::construction #%>% write_csv("data-out/LOADME-2.csv")
#> # A tibble: 9 × 9
#> Year Month `1 unit` `2 to 4 units` `5 units or more` Northeast Midwest South
#> <dbl> <chr> <dbl> <lgl> <dbl> <dbl> <dbl> <dbl>
#> 1 2018 Janua… 859 NA 348 114 169 596
#> 2 2018 Febru… 882 NA 400 138 160 655
#> 3 2018 March 862 NA 356 150 154 595
#> 4 2018 April 797 NA 447 144 196 613
#> 5 2018 May 875 NA 364 90 169 673
#> 6 2018 June 867 NA 342 76 170 610
#> 7 2018 July 829 NA 360 108 183 594
#> 8 2018 August 939 NA 286 90 205 649
#> 9 2018 Septe… 835 NA 304 117 175 560
#> # ℹ 1 more variable: West <dbl>
# total number of subjects interviewed per religion
tidyr::relig_income #%>% write_csv("data-out/LOADME-3.csv")
#> # A tibble: 18 × 11
#> religion `<$10k` `$10-20k` `$20-30k` `$30-40k` `$40-50k` `$50-75k` `$75-100k`
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Agnostic 27 34 60 81 76 137 122
#> 2 Atheist 12 27 37 52 35 70 73
#> 3 Buddhist 27 21 30 34 33 58 62
#> 4 Catholic 418 617 732 670 638 1116 949
#> 5 Don’t k… 15 14 15 11 10 35 21
#> 6 Evangel… 575 869 1064 982 881 1486 949
#> 7 Hindu 1 9 7 9 11 34 47
#> 8 Histori… 228 244 236 238 197 223 131
#> 9 Jehovah… 20 27 24 24 21 30 15
#> 10 Jewish 19 19 25 25 30 95 69
#> 11 Mainlin… 289 495 619 655 651 1107 939
#> 12 Mormon 29 40 48 51 56 112 85
#> 13 Muslim 6 7 9 10 9 23 16
#> 14 Orthodox 13 17 23 32 32 47 38
#> 15 Other C… 9 7 11 13 13 14 18
#> 16 Other F… 20 33 40 46 49 63 46
#> 17 Other W… 5 2 3 4 2 7 3
#> 18 Unaffil… 217 299 374 365 341 528 407
#> # ℹ 3 more variables: `$100-150k` <dbl>, `>150k` <dbl>,
#> # `Don't know/refused` <dbl>
# from gist ---------------------------------------------------------------
# source
# https://gist.github.com/avallecam/d20c91360baa7aa12e90757cf7cd787a
library(tidyverse)
library(purrr)
data <-
tibble(
hypertension = c(1,0,0,NA,0,NA,0),
asthma = c(1,0,1,1,NA,NA,0),
diabetes = c(1,0,1,0,NA,NA,1)
) %>%
mutate(id_patient = seq(1,nrow(.))) %>%
select(id_patient, everything())
# total number of comorbid illnesses present in per patient
data #%>% write_csv("data-out/LOADME.csv")
#> # A tibble: 7 × 4
#> id_patient hypertension asthma diabetes
#> <int> <dbl> <dbl> <dbl>
#> 1 1 1 1 1
#> 2 2 0 0 0
#> 3 3 0 1 1
#> 4 4 NA 1 0
#> 5 5 0 NA NA
#> 6 6 NA NA NA
#> 7 7 0 0 1
# ref: https://www.nature.com/articles/s41591-022-02156-9
# researched --------------------------------------------------------------
# are symptoms also valid as multimorbidity?
# cough
# fever
# dyspnea
# useful nut not
# tidyr::billboard # number entries are rankings, not reproduction number
# tidyr::population # sum of values across years is usually not useful
# tidyr::world_bank_pop # sum of values across years is usually not useful
```
<sup>Created on 2023-10-04 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment