[英]reverse loop interation in R like in Python
here is my python loop code with output这是我的 python 循环代码与 output
peaks =range(2,10)
for i in range(len(peaks) - 1, -1, -1):
print(i)
# 7,6,5,4,3,2,1,0
but i do not know how to do this with R但我不知道如何使用 R
suggest me please请给我建议
I agree with Sosel.我同意索塞尔。 Nevertheless, here is working code:不过,这里是工作代码:
peaks = 2:9
for(i in rev(0:(length(peaks)-1))) print(i)
in R在 R
peaks <- c(2:10)
l <- length(peaks)
result <- l - peaks
result[result > 0]
returns返回
7 6 5 4 3 2 1
if you nedd a for loop, you can use this:如果你需要一个 for 循环,你可以使用这个:
for(p in peaks){ifelse(l-p >= 0, print(l-p), NA)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.