【发布时间】:2019-04-24 15:19:31
【问题描述】:
希望使用向量中的值创建整数序列,seq = (x1:y1, x2:y2, x3:y3...xn:yn) where (x1
我尝试创建一个条件 if 语句和一个 for 循环,两者都导致....什么都没有。
x <- c(1, 10, 26, 40)
y <- c(5, 13, 30, 51)
通常情况下,我就足够了
seqq <- c(seq(x1,y1,1),seq(x2,y2,1)...)
但是当 n 是(或多或少)随机长度时,就会出现困难。尝试使用 for 循环,即
seqq <- c()
for (i in 1:length(x)){
seqq[i] <- seq(x[i], y[i],1) #I know this would technically create a vector of sequences
i <- i+1
}
#results in
Error in seq.default(x[i], y[i], 1) : 'from' must be a finite number
澄清我正在寻找
seqq <- c(1,2,3,4,5,10,11,12,13,26,27,28,29,30,40,...,51)
同样,if/while 语句实际上并没有做任何事情 有什么建议么?谢谢
【问题讨论】: