ifreak
ifreak

Reputation: 1756

subset data frame by skipping a specific number of rows

i have a very big data frame((35000 line) but i want to get specific rows by skipping for example 100 row.

so in this case each 100 row I'll just get one row.

i know that it can be done using:

N = nrow(dataframe)
   for( i in seq(1:N,by=100))
   { 
   out <- rbind(out, data.frame(...)

    }

is this can be done more easily than a for loop?? using subset or something like this

regards

Upvotes: 3

Views: 7445

Answers (2)

bnjmn
bnjmn

Reputation: 4584

You can create a vector and then subset on that vector like this:

temp <- seq(from = 1, to = N, by = 100)
df <- dataframe[temp,]

Upvotes: 2

Andrie
Andrie

Reputation: 179428

Use something like this:

dataframe[seq(1, nrow(dataframe), 100), ]

Upvotes: 10

Related Questions