本文介绍了提取向量的每个第 n 个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个向量,其中每个元素都是另一个向量的 i+6
元素.
I would like to create a vector in which each element is the i+6th
element of another vector.
例如,在长度为 120 的向量中,我想创建另一个长度为 20 的向量,其中每个元素的值都是 i, i+6, i+12, i+18...
的初始向量,即我想提取原始的每第 6 个元素.
For example, in a vector of length 120 I want to create another vector of length 20 in which each element is value i, i+6, i+12, i+18...
of the initial vector, i.e. I want to extract every 6th element of the original.
推荐答案
a <- 1:120
b <- a[seq(1, length(a), 6)]
这篇关于提取向量的每个第 n 个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!