请参见下面的dput()
。
这只是500个中的前10个ID。
我需要tx日期在其中的准入和退房日期。 例如1010008的发送日期属于admit17 / dc17。
每个ID最多可以输入55个录取/出院日期。需要为每个ID设置正确的入场/出场范围
输出应仅包含id,tx1,与tx1相对应的允许和排出
structure(list(id = c(1010001, 1010002, 1010004, 1010005, 1010006,
1010007, 1010008, 1010009, 1010010, 1010013), tx1 = structure(c(1145318400,
1211932800, 1235088000, 1119312000, 1244160000, 1096934400, 1154476800,
1169424000, 1139270400, 1025481600), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit1 = structure(c(1145232000, 1211760000,
1174435200, 1059523200, 1044144000, 1096848000, 1058918400, 1155686400,
1126656000, 1004140800), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc1 = structure(c(1147219200, 1213660800, 1178668800, 1061510400,
1047340800, 1097798400, 1059523200, 1155945600, 1126915200,
1004918400), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit2 = structure(c(NA, 1213833600, 1235001600, 1061683200,
1226534400, NA, 1062460800, 1167264000, 1139184000, 1005609600
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc2 = structure(c(NA,
1213920000, 1236643200, 1062460800, 1226707200, NA, 1062892800,
1167523200, 1140480000, 1006387200), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit3 = structure(c(NA, 1215129600,
1242172800, 1063756800, 1228953600, NA, 1067385600, 1167696000,
1140652800, 1006992000), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc3 = structure(c(NA, 1215561600, 1242345600, 1063929600,
1229644800, NA, 1067904000, 1168128000, 1140912000, 1007164800
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit4 = structure(c(NA,
1217116800, NA, 1066435200, 1231113600, NA, 1069200000, 1169424000,
1144627200, 1007424000), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc4 = structure(c(NA, 1217203200, NA, 1069200000, 1231372800,
NA, 1070409600, 1171843200, 1144800000, 1007596800), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit5 = structure(c(NA, 1218412800,
NA, 1070841600, 1244073600, NA, 1087689600, 1174348800, 1147132800,
1008720000), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc5 = structure(c(NA, 1219881600, NA, 1070928000, 1245024000,
NA, 1087862400, 1174348800, 1147737600, 1008892800), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit6 = structure(c(NA, 1220572800,
NA, 1073433600, 1248739200, NA, 1089417600, 1177372800, 1148860800,
1012176000), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc6 = structure(c(NA, 1222300800, NA, 1073520000, 1249948800,
NA, 1090627200, 1178409600, 1149033600, 1012262400), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit7 = structure(c(NA, 1223942400,
NA, 1089244800, 1250812800, NA, 1091059200, NA, 1291161600,
1025395200), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc7 = structure(c(NA, 1224201600, NA, 1089331200, 1251244800,
NA, 1092268800, NA, 1291334400, 1027296000), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit8 = structure(c(NA, 1225065600,
NA, 1089936000, 1317081600, NA, 1104796800, NA, 1319846400,
1029715200), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc8 = structure(c(NA, 1225324800, NA, 1090368000, 1317945600,
NA, 1105920000, NA, 1320969600, 1029888000), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit9 = structure(c(NA, 1231977600,
NA, 1098489600, NA, NA, 1109203200, NA, 1321228800, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc9 = structure(c(NA, 1232150400,
NA, 1099353600, NA, NA, 1109376000, NA, 1323043200, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit10 = structure(c(NA, 1247702400,
NA, 1115251200, NA, NA, 1113436800, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc10 = structure(c(NA, 1250121600,
NA, 1115510400, NA, NA, 1113868800, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit11 = structure(c(NA, 1250467200,
NA, 1119225600, NA, NA, 1119657600, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc11 = structure(c(NA, 1252022400,
NA, 1120521600, NA, NA, 1121126400, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit12 = structure(c(NA, 1253404800,
NA, 1136505600, NA, NA, 1132358400, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc12 = structure(c(NA, 1253750400,
NA, 1136592000, NA, NA, 1133395200, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit13 = structure(c(NA, 1255564800,
NA, 1141689600, NA, NA, 1136678400, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc13 = structure(c(NA, 1255651200,
NA, 1141862400, NA, NA, 1137542400, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit14 = structure(c(NA, 1256256000,
NA, 1228262400, NA, NA, 1137801600, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc14 = structure(c(NA, 1260748800,
NA, 1228435200, NA, NA, 1138060800, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit15 = structure(c(NA, NA,
NA, 1294272000, NA, NA, 1142208000, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc15 = structure(c(NA, NA, NA,
1294963200, NA, NA, 1142812800, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit16 = structure(c(NA, NA,
NA, NA, NA, NA, 1146096000, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc16 = structure(c(NA, NA, NA,
NA, NA, NA, 1146182400, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit17 = structure(c(NA, NA,
NA, NA, NA, NA, 1154390400, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc17 = structure(c(NA, NA, NA,
NA, NA, NA, 1157673600, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit18 = structure(c(NA, NA,
NA, NA, NA, NA, 1159228800, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), dc18 = structure(c(NA, NA, NA,
NA, NA, NA, 1159315200, NA, NA, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), admit19 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc19 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit20 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc20 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit21 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc21 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit22 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc22 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit23 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc23 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit24 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc24 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit25 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc25 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit26 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc26 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit27 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc27 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit28 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc28 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit29 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc29 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit30 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc30 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit31 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc31 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit32 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc32 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit33 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc33 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit34 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc34 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit35 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc35 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit36 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc36 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit37 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc37 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit38 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc38 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit39 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc39 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit40 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc40 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit41 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc41 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit42 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc42 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit43 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc43 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit44 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc44 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit45 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc45 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit46 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc46 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit47 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc47 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit48 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc48 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit49 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc49 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit50 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc50 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit51 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc51 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit52 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc52 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
admit53 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), dc53 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), admit54 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dc54 = structure(c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), admit55 = structure(c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), dc55 = structure(c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
答案 0 :(得分:1)
这是一个整洁的解决方案:
library(tidyverse)
df %>%
gather(col, val, -c(id, tx1)) %>%
separate(col, c("type", "round"), "(?<=[a-z])(?=[0-9])") %>%
filter(!is.na(val)) %>%
spread(type, val) %>%
filter(tx1 >= admit, tx1 <= dc)
首先,我收集id
和tx1
以外的所有列,以更轻松地一起使用列名。接下来,在这里使用tidyr::separate
将列名分为文本部分(“ type”)和数字部分(“ round”)。然后,我过滤掉NA
值,再次散开,并过滤掉介于两个之间的tx日期。
# A tibble: 10 x 5
id tx1 round admit dc
<dbl> <dttm> <chr> <dttm> <dttm>
1 1010001 2006-04-18 00:00:00 1 2006-04-17 00:00:00 2006-05-10 00:00:00
2 1010002 2008-05-28 00:00:00 1 2008-05-26 00:00:00 2008-06-17 00:00:00
3 1010004 2009-02-20 00:00:00 2 2009-02-19 00:00:00 2009-03-10 00:00:00
4 1010005 2005-06-21 00:00:00 11 2005-06-20 00:00:00 2005-07-05 00:00:00
5 1010006 2009-06-05 00:00:00 5 2009-06-04 00:00:00 2009-06-15 00:00:00
6 1010007 2004-10-05 00:00:00 1 2004-10-04 00:00:00 2004-10-15 00:00:00
7 1010008 2006-08-02 00:00:00 17 2006-08-01 00:00:00 2006-09-08 00:00:00
8 1010009 2007-01-22 00:00:00 4 2007-01-22 00:00:00 2007-02-19 00:00:00
9 1010010 2006-02-07 00:00:00 2 2006-02-06 00:00:00 2006-02-21 00:00:00
10 1010013 2002-07-01 00:00:00 7 2002-06-30 00:00:00 2002-07-22 00:00:00