开发者

R - is subset guaranteed to return the same order of values in repeated calls?

开发者 https://www.devze.com 2023-03-28 18:34 出处:网络
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

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消