[R] duplicated() on zero-column data frames returns empty

Mark Webster m@rkweb@ter204 @end|ng |rom y@hoo@co@uk
Sun Apr 7 22:44:26 CEST 2024


 With respect to duplicated.data.frame taking account of row names to return all the rows as unique: thinking about this some more, I can see that making sense in isolation, but it's at odds with the usual behaviour of duplicated for other classes, e.g. primitive vectors, where it doesn't take account of names.
> Would you suggest similar changes to duplicated.matrix too? Currently
> it too returns 0-length output for 0-column inputs:

duplicated.matrix is an interesting one. I think a similar change would make sense, because it would have the dimensions that people would expect when using the default MARGIN = 1. However, it could be argued that it's not a needed change, because the Value section of its documentation only guarantees the dimensions of the output when using MARGIN = 0. In that case, duplicated.matrix does indeed return the expected 5x0 matrix for your example:
str(duplicated(matrix(0, 5, 0), MARGIN = 0))# logi[1:5, 0 ]
Best Regards,
Mark Webster  
	[[alternative HTML version deleted]]



More information about the R-help mailing list