When 开发者_运维技巧subsetting a data.frame or vector, is the same subset call guaranteed to return the same order of values/rows no matter how many times the call is made?
For a vector, definitely yes. From the documentation for subset:
For ordinary vectors, the result is simply
x[subset & !is.na(subset)]
.
For data frames, the same would appear to be true, since the subsetting is just applied to each row effectively as a vector. For instance, the following will always return just entries from the b
column of d
whose corresponding a
value is greater than 5. No reordering of rows occurs.
d <- data.frame(a=1:10, b=20:29)
subset(d, a>5, b)
精彩评论