用于选择除第一行之外的所有行的 R 语法 [英] R syntax for selecting all but two first rows
本文介绍了用于选择除第一行之外的所有行的 R 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何选择除前两行之外的所有行,例如mtcars 数据集?
How do I select all but the first two rows from e.g. the mtcars dataset?
我知道我可以编写 no_mazda <- mtcars[3:32]
,只要我知道行数,它就可以工作.但是当我不知道我需要写的行数时,例如no_mazda <- mtcars[3:nrow(mtcars)]
哪个原因也有效,但是:
I know that I can write no_mazda <- mtcars[3:32]
, which does work as long as I know the number of rows. But when I don't know the number of rows I need to write e.g. no_mazda <- mtcars[3:nrow(mtcars)]
which of cause also works, but:
R 是否提供比包含两次 mtcars
的表达式更智能的语法?
Does R provide a smarter syntax than an expression that includes mtcars
twice?
推荐答案
我更喜欢使用 tail
和 n
的负值:
I prefer using tail
with negative values for n
:
tail(mtcars,-2)
这篇关于用于选择除第一行之外的所有行的 R 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文