Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 python 中,可以像这样对列表进行切片x[4:-1]以从第四个元素到最后一个元素。
x[4:-1]
在 R 中x[4:length(x)],对于具有类似x[,,,,4:dim(x)[5],,,]. 对于从中间元素到最后一个元素的特定维度的数组切片,这是更优雅的语法吗?
x[4:length(x)]
x[,,,,4:dim(x)[5],,,]
谢谢
您可以使用放置元素语法:
> (1:10)[-(1:4)] [1] 5 6 7 8 9 10
如果您有兴趣对数组的最后 n 个元素进行切片,则可以使用:
x[seq(length=n, from=length(x), by=-1)]