Is R a subset guaranteed to return the same order of values ​​on repeated calls?

With a subset of data.frame or vector, is the same call to the subset guaranteed to return the same order of values ​​/ rows regardless of how many times the call has been made?

+4
source share
1 answer

For a vector, definitely yes. From the documentation for the subset:

For ordinary vectors, the result is simply x[subset & !is.na(subset)] .

For data frames, the same will be displayed as true, since a subset simply applies to each row effectively as a vector. For example, the following will always return only records from column b d , the corresponding value of a greater than 5. There is no row reordering.

 d <- data.frame(a=1:10, b=20:29) subset(d, a>5, b) 
+4
source

All Articles