transfer from old repo
This commit is contained in:
parent
cfa4a5f9cc
commit
277e2b8cf3
1111 changed files with 83736 additions and 0 deletions
49
2 Longterm/data_import_files.R
Normal file
49
2 Longterm/data_import_files.R
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# Specifying needed data collection files
|
||||
data_source <- c(
|
||||
"PASE_rev_v13.dta",
|
||||
"MFI_rev_v13.dta",
|
||||
"mdi_rev_v13.dta",
|
||||
"mmse_rev_v13.dta",
|
||||
"mrs_rev_v13.dta",
|
||||
"SDMT_rev_v13.dta",
|
||||
"who_rev_v13.dta"
|
||||
)
|
||||
|
||||
## Cumulated data
|
||||
dta<-read.csv("/Volumes/Data/exercise/source/background.csv",colClasses = "character", na.strings = c("NA","","unknown"))
|
||||
|
||||
# Getting full filenames
|
||||
file_nms <- list.files("/Volumes/Data/STATA13",full.names = TRUE)[match(data_source,list.files("/Volumes/Data/STATA13"))]
|
||||
|
||||
# Loading datafiles
|
||||
|
||||
dta<-read.csv("/Volumes/Data/exercise/source/background.csv",colClasses = "character", na.strings = c("NA","","unknown"))
|
||||
|
||||
ls <- lapply(file_nms,function(i){
|
||||
d <- read_dta(i)
|
||||
colnames(d) <- tolower(gsub("instance","INSTANCE",colnames(d))) #in the sdmt dataset, instance column is lower case
|
||||
d
|
||||
})
|
||||
|
||||
# Selecting desired variables
|
||||
ls_sel <- lapply(seq_along(ls), function(i) {
|
||||
ls[[i]] |> select(cpr,
|
||||
SYS_SITE,
|
||||
INSTANCE,
|
||||
starts_with("TALOS_")) |> as_factor() |>
|
||||
full_join(select(dta,cpr, rnumb)) |> select(rnumb,everything())
|
||||
})
|
||||
|
||||
# Naming lists according to file names
|
||||
names(ls_sel) <- tolower(unlist(lapply(data_source,function(x){strsplit(x,"_")[[1]][1]})))
|
||||
|
||||
## Screening list and EOS data
|
||||
subjects <- read_dta("/Volumes/Data/STATA13/inkl_rev_v13.dta") |>
|
||||
select(c("cpr", "rnumb", "rdate", "rtreat")) |>
|
||||
filter(rnumb != 999) |>
|
||||
left_join(read_dta("/Volumes/Data/STATA13/end_rev_v13.dta") |>
|
||||
select(c("cpr", "TALOS_end00", "TALOS_end01"))
|
||||
) |>
|
||||
rename(enddate = TALOS_end00,
|
||||
eos_early = TALOS_end01) |>
|
||||
as_factor()
|
||||
Loading…
Reference in a new issue