Search code examples
rsyntaxrow

R syntax for selecting all but two first rows


How do I select all but the first two rows from e.g. the mtcars dataset?

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:

Does R provide a smarter syntax than an expression that includes mtcars twice?


Solution

  • I prefer using tail with negative values for n:

    tail(mtcars,-2)