From 95205580367e094a4984ab5515a996bfa9c770b5 Mon Sep 17 00:00:00 2001 From: KingArthur0205 Date: Wed, 27 Nov 2024 11:45:00 +0000 Subject: [PATCH] CHEXI_Lin_2019.r --- data/CHEXI_Lin_2019.r | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 data/CHEXI_Lin_2019.r diff --git a/data/CHEXI_Lin_2019.r b/data/CHEXI_Lin_2019.r new file mode 100644 index 0000000..f6fa0cd --- /dev/null +++ b/data/CHEXI_Lin_2019.r @@ -0,0 +1,17 @@ +# Data: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/YRLEAY +library(haven) +library(dplyr) +library(tidyr) +library(openxlsx) +library(readxl) + +df <- read_excel("no_Names_coding-0623_forupload.xlsx", sheet = "data") +df$id <- seq_len(nrow(df)) +df <- df |> + select(id, starts_with("item")) +df[df == 9999] <- NA +df <- df[!apply(df[, -which(names(df) == "id")], 1, function(row) all(is.na(row))), ] +df <- pivot_longer(df, col=-id, values_to="resp", names_to="item") + +save(df, file="CHEXI_Lin_2019.Rdata") +write.csv(df, "CHEXI_Lin_2019.csv", row.names=FALSE)