getting duplicated column names after binding data tables

Dear R experts,

I tried to bind two data tables by following commands
xy=rbindlist(list(setDT(x),setDT(y)),fill=T)

The data can be downloaded from the link below
https://drive.google.com/drive/folders/1nLfwiKnHnQVPE3tGCEx5kiztbxFklWHa?usp=sharing

My question is why I ended up getting duplicated columns instead of one column of longer length in the new data table (i.e., xy). Besides, Thanks

Best,
Veda

I downloaded the two files but could not open them.
This is maybe related to I’m able to save .rds files, but I’m unable to re-load them .
In a standard session I get the message
Error in readRDS("x.RData") : unknown input format
and in the reprex a more extended message (see below).

Using two small data.frames I saw no problems, so your syntax is okay.

library(data.table)

x= readRDS("x.RData")
#> Warning in gzfile(file, "rb"): cannot open compressed file 'x.RData', probable
#> reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection
y= readRDS("y.RData")
#> Warning in gzfile(file, "rb"): cannot open compressed file 'y.RData', probable
#> reason 'No such file or directory'
#> Error in gzfile(file, "rb"): cannot open the connection

x= data.frame(
  f1=c(1,2,3),
  f2=c('a','b','c')
)
x = as.data.table(x)

y= data.frame(
  f1=c(4,5,6),
  f2=c('d','e','f')
)
y = as.data.table(y)

xy=rbindlist(list(setDT(x),setDT(y)),fill=T)

xy
#>    f1 f2
#> 1:  1  a
#> 2:  2  b
#> 3:  3  c
#> 4:  4  d
#> 5:  5  e
#> 6:  6  f

Created on 2020-06-11 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.