0

I am having a hard time combining these datasets and it's because the names of the variables are different. How would I do this?

[I want to combine this, but the response I get from R is "Error in match.names(clabs, names(xi)) : names do not match previous names"]

img

Also, I understand that some of the variables are named differently but they mean the same thing. I do have the same number of variables in each dataset.

SternK
  • 11,649
  • 22
  • 32
  • 46
  • 3
    Welcome to Stack Overflow. We cannot read code or data into R from images. Please [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including code and a small representative dataset in a plain text format. – neilfws Jun 16 '23 at 03:46
  • 1
    `data.table::rbindlist(list(dat1, dat2, dat3), use.names = FALSE)` – SamR Jun 16 '23 at 07:09
  • 1
    Hello. Have you tried just renaming them to have a consistent name scheme? – Paul Stafford Allen Jun 16 '23 at 07:09

1 Answers1

0

You could temporarily convert the dataframes to matrices and switch back after rbinding:

econ1 <- data.frame(a = 1, b = 2)
econ2 <- data.frame(c = "a", d = NA)


list(econ1, econ2) |>
  Map(f = as.matrix) |>
  Reduce(f = rbind) |>
  as.data.frame()
  a    b
1 1    2
2 a <NA>

Note that names will be taken from the first dataframe in line, and modes (numeric, character ...) will be changed to accomodate all incoming data. E. g. column a in above example is character.

I_O
  • 4,983
  • 2
  • 2
  • 15