How to remove duplicated (by name) column in data.tables in R? -


while reading data set using fread, i've noticed i'm getting duplicated column names, example (fread doesn't have check.names argument)

> data.table( x = 1, x = 2)    x x 1: 1 2 

the question is: there way remove 1 of 2 columns if have same name?

how about

dt[,unique(names(dt)),with=false] 

? ?data.table:

j: single column name, single expresson of column names, ‘list()’ of expressions of column names, expression or function call evaluates ‘list’ (including ‘data.frame’ , ‘data.table’ ‘list’s, too), or (when ‘with=false’) vector of names or positions select.

this selects first occurrence of each name (i'm not sure how want handle this).

as @davidarenburg suggests in comments above, use check.names=true in data.table() (however, don't see check.names option in fread() -- maybe i'm missing something).


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -