【发布时间】:2012-06-08 15:48:22
【问题描述】:
我知道这个问题的标题很混乱,如果没有错的话。对不起,让我解释一下我想做什么:
# I have a population of individuals:
population <- c("Adam", "Bob", "Chris", "Doug", "Emily", "Frank", "George","Harry", "Isaac", "Jim", "Kyle", "Louis")
population_size <- length(population) # this is 12
# I then draw a sample from this population
mysample_size <- 5
mysample <- sample(population,mysample_size, replace=FALSE)
# I then simulate a network among the people in the sample
frn <- matrix(rbinom(mysample_size*mysample_size, 1, 0.4),nrow=n)
x[x<=0] <- 0
x[x>0] <- 1
rownames(frn) <- mysample
colnames(frn) <- mysample
*我现在想将 frn 中的值转移到一个包含原始总体中所有成员的矩阵中,即 12 x 12 矩阵。该矩阵中的值仅来自 frn 5*5 矩阵。
我不知道如何从顶部的矩阵生成底部的矩阵。
我想过不同的方法(例如,使用 iGraph 和通过边缘列表推进)或运行循环,但并没有真正找到一个运行的替代方案。了解背景可能很重要:我的实际矩阵比这大得多,我需要多次运行此操作,因此一个有效的解决方案会很棒。非常感谢您的帮助。
【问题讨论】:
-
什么是
x以及它如何适应这里?而nrow=n中的n应该是nrow=mysample_size,对吧? -
感谢您的编辑。你是对的。它应该是“nrow=mysample_size” 需要将 x 替换为 frn。我的错。对不起。感谢您的关注
标签: r social-networking sparse-matrix