对不起基本问题,但我需要将偏移量为1的数字列表分区。 例如。, 我有一个列表:
c(194187, 193668, 192892, 192802 ..)
并需要一个列表列表,如:
c(c(194187, 193668), c(193668, 192892), c(192892, 192802)...)
其中列表n的最后一个元素是列表n + 1的第一个元素。必须有办法做到这一点 分裂() 但我无法弄清楚 在mathematica中,我需要的命令是Partition [list,2,1]
答案 0 :(得分:0)
你可以尝试这样,使用动物园图书馆
class SeekingForm(forms.ModelForm):
class Meta:
model = Seeking
widgets = {'m2m_field': forms.CheckboxSelectMultiple}
exclude = (
'entity',
)
def __init__(self, *args, **kwargs):
super(SeekingForm, self).__init__(*args, **kwargs)
self.fields["company_type"].widget = forms.CheckboxSelectMultiple()
输出:
library(zoo)
x <- 1:10 # Vector of 10 numbers
m <- rollapply(data = x, 2, by=1, c) # Creates a Matrix of rows = n-1, each row as a List
l <- split(m, row(m)) #splitting the matrix into individual list
答案 1 :(得分:0)
以下是使用base R
创建vector
元素
v1 <- rbind(x[-length(x)], x[-1])
c(v1)
#[1] 194187 193668 193668 192892 192892 192802
如果我们需要list
split(v1, col(v1))
x <- c(194187, 193668, 192892, 192802);