Skip to content

Instantly share code, notes, and snippets.

@Protonk
Last active November 16, 2023 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Protonk/32bcb49231a851f8960b6282ce02fa2c to your computer and use it in GitHub Desktop.
Save Protonk/32bcb49231a851f8960b6282ce02fa2c to your computer and use it in GitHub Desktop.
Allergy example
food.allergy.analysis.Zenodo <- read.csv("~/Downloads/food-allergy-analysis-Zenodo.csv")
allergyDF <- food.allergy.analysis.Zenodo[, c("SUBJECT_ID", "BIRTH_YEAR", "GENDER_FACTOR", "RACE_FACTOR", "ETHNICITY_FACTOR", "PAYER_FACTOR", "AGE_START_YEARS", "AGE_END_YEARS")]
allergyDF[, "SPAN_IN_YEARS"] <- with(food.allergy.analysis.Zenodo, AGE_END_YEARS - AGE_START_YEARS)
allergyDF[, "SOY_SPAN"] <- with(food.allergy.analysis.Zenodo, SOY_ALG_END - SOY_ALG_START)
allergyDF[, "MILK_SPAN"] <- with(food.allergy.analysis.Zenodo, MILK_ALG_END - MILK_ALG_START)
allergyDF[, "FISH_SPAN"] <- with(food.allergy.analysis.Zenodo, FISH_ALG_END - FISH_ALG_START)
allergyDF[, "SHELLFISH_SPAN"] <- with(food.allergy.analysis.Zenodo, SHELLFISH_ALG_END - SHELLFISH_ALG_START)
allergyDF[, "PEANUT_SPAN"] <- with(food.allergy.analysis.Zenodo, PEANUT_ALG_END - PEANUT_ALG_START)
with(allergyDF[allergyDF[,"PEANUT_SPAN"] > 0, ],
plot(SPAN_IN_YEARS, PEANUT_SPAN, ylim = c(0, 12)))
with(allergyDF[allergyDF[,"PEANUT_SPAN"] > 0, ],
hist(PEANUT_SPAN))
with(allergyDF,
plot(SPAN_IN_YEARS, PEANUT_SPAN, ylim = c(0, 12)))
with(allergyDF[allergyDF[,"SHELLFISH_SPAN"] > 0, ],
plot(SPAN_IN_YEARS, SHELLFISH_SPAN, ylim = c(0, 12)))
library(readr)
Allergen_Status_of_Food_Products <- read_csv("~/Downloads/Allergen_Status_of_Food_Products.csv")
library(stringr)
asplit(str_split_fixed(Allergen_Status_of_Food_Products$Allergens,", ", 3), 1) -> allerVec
allerVec <- unlist(allerVec)
allerCol <- Allergen_Status_of_Food_Products$Allergens
dummyAl <- data.frame("Allergen" = allerCol)
dummyAl$Dairy <- as.integer(grepl("Dairy", allerCol))
dummyAl$Wheat <- as.integer(grepl("Wheat", allerCol))
dummyAl$Fish <- as.integer(grepl("Fish", allerCol))
dummyAl$Soybeans <- as.integer(grepl("Soybeans", allerCol))
dummyAl$Shellfish <- as.integer(grepl("Shellfish", allerCol))
Allergen_Status_of_Food_Products <- cbind(Allergen_Status_of_Food_Products, dummyAl[, -1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment