Is deleting all rows in an R data frame using [-0,] officially supported? -
i have found can delete rows of r data frame subsetting square bracket function , using -0 row index. however, have not been able find documentation saying official behavior can count on being there in future. official function can use confidence expecting continue function way in future releases?
> df <- data.frame(c1=c(1,2,3),c2=c(2,3,4), c3=c(4,5,6)) > df c1 c2 c3 1 1 2 4 2 2 3 5 3 3 4 6 > df[-0,] [1] c1 c2 c3 <0 rows> (or 0-length row.names)
let's check documentation.
help("[.data.frame") says (emphasis mine):
when [ , [[ used 2 indices (x[i, j] , x[[i, j]]) act indexing matrix [...]. note each selected column, xj say, typically (if not matrix-like), the resulting column xj[i], , hence rely on corresponding [ method, see examples section.
next stop help("["), doesn't using 0 index, points ‘r language definition’ manual.
there read (emphasis mine):
a special case 0 index, has null effects: x[0] empty vector , otherwise including zeros among positive or negative indices has same effect if omitted.
in summary:
since behavior documented, can rely on df[0,] returning data.frame empty column vectors.
Comments
Post a Comment