Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

R iGraph remove vertices with attribute value = NA

I'm trying to remove all vertices from a graph which have the value "NA" in the attribute "concreteness". I've tried using the following code:

G.concrete <- delete.vertices(g, V(g)$concreteness[V(g)$concreteness, value = "NA"])

but no luck.

For example if we take the concreteness values to be:

concreteness <- c(NA, 0.1, 0.2, 0.3, 0.4, NA, 0.4, 0.3, 0.2, 0.1)

And then set them as attributes using:

g <- make_ring(10) %>%
set_vertex_attr("concreteness", value = concreteness)

We would have two vertices which would need to be removed. These "NA" values register as "TRUE" when queried using is.na().

Thanks,

Peter

question from:https://stackoverflow.com/questions/65913633/r-igraph-remove-vertices-with-attribute-value-na

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To select all vertices with NA values for concreteness you can do

V(g)[is.na(concreteness)]

and to delete them, use

delete.vertices(g, V(g)[is.na(concreteness)])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...