I have a big Excel table, which has information about different departments - mostly Dates. What I've done til yet, was to extract the dates manually and calculate with them. It works pretty well but it is hard coded:
# Departement 1
aufnahmediagnose_days_abteilung1 <- as.Date(as.character(dat$ad_first[1:2]), format="%Y-%m-%d") - as.Date(as.character(dat$ad_occ[1:2]), format="%Y-%m-%d")
aufnahmediagnose_days_abteilung1 <- na.omit(aufnahmediagnose_days_abteilung1)
aufnahmediagnose_days_abteilung1 <- as.numeric(sum(aufnahmediagnose_days_abteilung1) / length(aufnahmediagnose_days_abteilung1))
# Dempartment 2
aufnahmediagnose_days_abteilung2 <- as.Date(as.character(dat$ad_first[3:5]), format="%Y-%m-%d") - as.Date(as.character(dat$ad_occ[3:5]), format="%Y-%m-%d")
aufnahmediagnose_days_abteilung2 <- na.omit(aufnahmediagnose_days_abteilung2)
aufnahmediagnose_days_abteilung2 <- as.numeric(sum(aufnahmediagnose_days_abteilung2) / length(aufnahmediagnose_days_abteilung2))
Like you can see, I am using the hardcoded index, f.e. [3:5] (because this is one of the departments that I am looking for). The difference between the first and the second department is the information in the first column (record_id
), like you can see in the following head of the table:
record_id redcap_event_na⦠department his has_dob has_sex has_ad has_hd has_icdnd
<dbl> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 fall_1_arm_1 1 Orbis 1 1 1 1 1
2 1 fall_2_arm_1 NA NA NA NA NA NA NA
3 2 fall_1_arm_1 NA NA NA NA NA NA NA
4 2 fall_2_arm_1 NA NA NA NA NA NA NA
5 2 fall_3_arm_1 NA NA NA NA NA NA NA
The columns that i need (ad_first
and ad_occ
) are not visible here, because I just display the head. The first 2 rows got the RecordID 1.
How can I choose the exact rows from ad_first
and ad_occ
, when the condition is, that I want to have the rows, where the RecordID
equals 1?