2

I have a data frame with 100 entries, and I want to get a fields value for a subset of the entries. Specifically, I want every other 10 entries (i.e. indices 1-10,21-30,41-50,61-70,...)

The only way I've been able to do this is via: c(data$field[1:10],data$field[21:30],...)

But this seems like a horrible solution, especially if the size of the data frame changes.

4

1 に答える 1

5

できるよ

data$field[rep(c(TRUE, FALSE), each = 10)]

ここで、10の後に10が続くrepベクトルを作成し、インデックス作成に使用するときに必要に応じてリサイクルされます。TRUEFALSE

于 2013-02-10T04:17:49.080 に答える