我正在尝试创建一个函数,用户可以在其中选择他们想要使用的运算符,从而产生不同的输出。但我似乎无法让它发挥作用。我知道我们不能将运算符分配给 R 对象,然后根据 R 对象名称将其用作运算符。有没有办法做到这一点?或者也许是编写函数的更好方法?
test <- function(items, operator = "+"){
bank_alpha <- matrix(ncol=6)
colnames(bank_alpha) <- colnames(bank_alpha, do.NULL = FALSE, prefix = "Q")
colnames(bank_alpha)[6] <- "A"
alphabet <- LETTERS[seq(1:26)]
for (i in 1:items) {
item <- c(alphabet[i], alphabet[i operator 1], alphabet[i operator 2], alphabet[i operator 3], alphabet[i operator 4], alphabet[i operator 5])
bank_alpha <- rbind(bank_alpha, item)
bank_alpha <- na.omit(bank_alpha)
}
return(bank_alpha)
}
test(items=4, operator = "-")
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建节点,当鼠标悬停在节点上时,这些节点会改变颜色.
我使用R(igraph)绘制节点并生成网络.
然后我使用cat()创建一个html模板.
但是,我不知道如何链接css表来创建应位于节点顶部的悬停按钮.
require(igraph)
htmlfile = file.path('~/Dropbox/Cambridge/PhD/ICAR/AIG/Map/html/', "page1.html")
cat("<html><h1>My first HTML page from R</h1>",file = htmlfile)
cat("\n<br>Hello Web World!", append = TRUE, file = htmlfile)
set.seed(1)
E.circuit.2 <- graph_from_literal(1--2:3:4:5, 2--3,3--2, 4--5)
E.circuit.2
coordinates <- layout_with_dh(E.circuit.2)
coordinates
plot(E.circuit.2)
cat('\n<p><img src="map.png", align="center"></p>', append = TRUE, file = htmlfile)
cat("\n</html>", append = TRUE,file = htmlfile)
Run Code Online (Sandbox Code Playgroud) 无论从对象'd'中选择什么字母,我都试图为节点6和7着色.
g <- graph_from_literal(1:2:3:4:5 -- 6:7)
# Rename (sum up all the vertices)
d <- c("a", "b", "c", "d", "e", "f", "g","h", "i", "j")
V(g)$name <- sample(d, 7, replace=TRUE)
colours <- c("red")
V(g)$color <- ifelse(V(g)$name == c('a','e'), "white", colours)
plot.igraph(g, layout=layout_with_dh, vertex.label=V(g)$name,
vertex.size=35,
vertex.color=V(g)$color, #colors.r
vertex.label.cex=0.7,
)
Run Code Online (Sandbox Code Playgroud)
我尝试了上面的ifelse(),但它们似乎没有取数值.我很感激一些帮助.
我想要的是节点6例如是白色而7是例如绿色而其他节点是红色的.
谢谢!