我使用rnorm模拟数据,但我需要设置一个上限和下限,有谁知道如何做到这一点?
码:
rnorm(n = 10, mean = 39.74, sd = 25.09)
Run Code Online (Sandbox Code Playgroud)
上限需要为340,下限为0
我问这个问题,因为我正在将SAS代码重写为R代码.我从未使用过SAS.我正在尝试重写以下代码:
sim_sample(simtot=100000,seed=10004,lbound=0,ubound=340,round_y=0.01,round_m=0.01,round_sd=0.01,n=15,m=39.74,sd=25.11,mk=4)
Run Code Online (Sandbox Code Playgroud) 我需要计算我在R中制作的网络的一个巨大组件,但是在这个网站上给出的代码(http://lists.gnu.org/archive/html/igraph-help/2009-08/msg00064.html)导致奇怪的输出.我需要巨大的组件来计算亲密度(根据大学老师的说法)
giant.component <- function(graph) {
cl <- clusters(graph)
induced.subgraph(graph, which(cl$membership == which.max(cl$csize)-1)-1)}
G <- giant.component(as.igraph(Q))
Run Code Online (Sandbox Code Playgroud)
结果:
IGRAPH U-W- 0 0 --
+ attr: frame.color (v/c), label.color (v/c), label (v/c), shape
(v/c), color (v/c), size (v/n), size2 (v/n), weight (e/n),
arrow.mode (e/n), curved (e/n), color (e/c), label (e/c), lty
(e/n), width (e/n)
Run Code Online (Sandbox Code Playgroud)
Csardi建议的代码调整会产生以下代码和结果:
model5 <- matrix(c(0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …Run Code Online (Sandbox Code Playgroud)