我正在处理一些航运数据,其中包含有关船舶航行的信息。每个航次都有自己的 ID,通常一艘船在某个港口开始航行,在同一个或不同的港口装载货物,然后在某个港口卸货。有时,船舶可能还必须在港口等待装卸货物。此外,船舶可以在多个港口卸货。我的数据集的前 10 行如下:
structure(list(Fkey_Dim_Voyage_Id = c(1228L, 1228L, 1228L, 1656L,
1656L, 1656L, 1675L, 1675L, 1675L, 1675L), Imos_VoyNo = c(19L,
19L, 19L, 16L, 16L, 16L, 7L, 7L, 7L, 7L), ord_no_int = c(100,
300, 500, 100, 200, 700, 100, 300, 500, 600), Fkey_Dim_PortFunction_Id = c("Commencing",
"Loading", "Discharging", "Commencing", "Loading", "Discharging",
"Commencing", "Loading", "Discharging", "Discharging"), PortName = c("CHESAPEAKE",
"CHESAPEAKE", "IMMINGHAM", "BELLEDUNE", "PORT CARTIER", "IMMINGHAM",
"AUGHINISH", "NORFOLK", "LA SPEZIA", "FUSINA"), Fkey_Dim_Vessel_Id = c(1179L,
1179L, 1179L, 144L, 144L, 144L, 1124L, 1124L, 1124L, 1124L),
Date_Arrival = structure(c(978307200, 1511927640, 1513400760,
978307200, 1510578000, 1511956800, 978307200, 1511611260,
1513713600, 1515225600), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Date_Departure = structure(c(1511945640, 1512267840, 1516425480,
1510489380, 1510765200, 1513359300, 1510665120, 1512283320,
1514903400, 1515664800), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
Latitude = c(36.45, 36.45, 53.38, 47.54, 50, 53.38, 52.38,
36.51, 44.06, 45.25), Longitude = c(-76.15, -76.15, -0.11,
-65.45, -66.47, -0.11, -9.03, -76.18, 9.49, 12.16)), row.names = c(NA,
-10L), class = c("grouped_df", "tbl_df", "tbl", "data.frame"), vars = c("Fkey_Dim_Voyage_Id",
"Imos_VoyNo"), drop = TRUE, indices = list(0:2, 3:5, 6:9), group_sizes = c(3L,
3L, 4L), biggest_group_size = 4L, labels = structure(list(Fkey_Dim_Voyage_Id = c(1228L,
1656L, 1675L), Imos_VoyNo = c(19L, 16L, 7L)), row.names = c(NA,
-3L), class = "data.frame", vars = c("Fkey_Dim_Voyage_Id", "Imos_VoyNo"
), drop = TRUE))
我正在尝试使用 R 中的visNetwork
origraph
包将这些信息可视化为网络图。但是为了做到这一点,我想将PortName
变量分成 From
和To
变量并维护端口函数的属性,即。开始、装载、等待或卸货。for
我试图通过遍历每个唯一的 Voyage ID来使用循环来实现这一点,但徒劳无功。不值得分享损坏的代码。任何指示或建议都会有所帮助。