This answer warns of some scary behavior from which
. Specifically, if you take any data frame, say df <- data.frame(x=1:5, y=2:6)
, and then try to subset it with something that evaluates to which(FALSE)
(i.e. integer(0)
), then you will delete every column in the data set. Why is this? Why would dropping all columns that correspond to integer(0)
delete everything? Deleting nothing shouldn't destroy everything.
Example:
>df <- data.frame(x=1:5, y=2:6)
>df
x y
1 1 2
2 2 3
3 3 4
4 4 5
5 5 6
>df <- df[,-which(FALSE)]
>df
data frame with 0 columns and 5 rows