-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
Hi! I expected that dcast(DT, .~column) should always output a data table that has columns named unique(paste(DT$column)) but here is a counter-example:
> x=c("NA","",NA,"foo");DT=data.table(x);out=dcast(DT,.~x,length)
> x
[1] "NA" "" NA "foo"
> names(out)
[1] "." "NA" "V1" "NA" "foo"
> out
. NA V1 NA foo
1: . 1 1 1 1The issue above is that the empty string value is mapped to the column name V1, which is confusing. I would propose to fix by changing that output column name to empty string, as below:
> setnames(out,c(".","NA","","NA","foo"))
> out
. NA NA foo
1: . 1 1 1 1Another thing I noticed is that both NA (missing value) and "NA" (string) map to two different columns (with the same name, "NA"), is that normal? (should there be a warning if dcast outputs columns with the same name?)