我有一个特定长度的字符向量(不应更改),如下所示:
my.vec <- rep("free", 40000)
我现在需要做的是:
- 我需要通过向量循环22来表示年度发展(1循环=1年)
- 在每个循环中,向量的7个随机元素应从
"free"
变为"occupied"
- 在两个
"occupied"
个元素之间,应该保持至少4个"free"
个元素(即"occupied" "free" "free" "free" "free" "occupied"
个 - 如果一个元素在一个循环中被指定为
"occupied"
,则不再可用于下一个循环
为了更清楚起见,下面是一个具有短向量和三个时间步长的示例:
# this is the intital vector:
my.vec <- rep("free", 200)
# this is the assignment in the first three time steps:
# first time step
my.vec[c(1,25,18,10,48,41,33)] <- "occupied"
# second time step
my.vec[c(98,91,81,63,70,163,120)] <- "occupied"
# third time step
my.vec[c(199,127,150,140,172)] <- "occupied"
我希望事情变得明朗起来. 有谁知道如何实现这一点吗?