예제 그래프를 사용하여 루트 및 터미널 정점을 식별하고 다른 정점의 레이블을 제거합니다. 여기에 초기 그래프의 모습입니다 : 이제
set.seed(2)
plot(g2)

하는의는 중간 정점
# Get all edges
e = get.edgelist(g2)
# Root vertices are in first column but not in second column
root = setdiff(e[,1],e[,2])
# Terminal vertices are in second column but not in first column
terminal = setdiff(e[,2], e[,1])
# Vertices to remove are not in root or terminal vertices
remove = setdiff(unique(c(e)), c(root, terminal))
# Remove names of intermediate vertices
V(g2)$name[V(g2)$name %in% remove] = ""
set.seed(2)
plot(g2)

원래 응답의 이름을 식별하고 제거 할 수
set.vertex.attribute
을 사용하여 레이블 이름을 변경할 수 있습니다.
library(igraph)
# Create a graph to work with
g = graph_from_edgelist(cbind(c(rep(1,10),2:11), c(2:21)))
plot(g)

이제 우리는 중간 정점에서 라벨을 제거 할 수 있습니다 : 예를 들면 다음과 같습니다이다
g = set.vertex.attribute(g, "name", value=c(1,rep("", length(2:11)),12:21))
plot(g)

당신은 작업 할 샘플 그래프를 제공 할 수 있습니까? – eipi10
예제 그래프에는 루트 중간 터미널 구조가 아니라 연결된 꼭지점 쌍만 있습니다. – eipi10
안녕하세요. 죄송합니다. 샘플 세트를 고정시켜 중간 정점을 갖도록했습니다. 귀하의 예를 들어 주시면 감사하겠습니다 만, 제 대규모 데이터 세트에 효과적으로 적용하기가 어렵습니다. – hmnoidk