0

I have datasets that have four common string characters "GTAH" in their names. All the data are in the same working directory. Some of the data have a different number of columns due to additional variables for some of the datasets. However, about 95% of all variables in the datasets are the same. I want to append or bind all the data with this common string character into a single data frame. The list below is an example of the data names in the folder or directory:

XOGTHA213.DTA
ABGTHA587.DTA
IRGTHA987.DTA
CDGTHA398.DTA
NJGTHA783.DTA
KEGTHA197.DTA
DEGTHA037.DTA
SCGTHA002.DTA
Ekow_ababio
  • 163
  • 9
  • 1
    like this? `paste0("GTAH", your_vector)` – Maël Feb 02 '23 at 16:35
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 02 '23 at 16:36
  • 1
    Are those files on disk? What command do you use to read them? It's not clear how a `DTA` file is formatter. You can grab all the files names with `list.files(pattern="GTAH")` or something like that. And you can apply whatever reading function you use to those matching names. Not sure what you want the output to look like if the files have different numbers of columns. – MrFlick Feb 02 '23 at 16:38
  • 2
    Suggested duplicate [How to make a list of data frames?](https://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames). My answer there covers (a) using `list.files()` to get file names, (b) importing all the data from those files as data frames, and (c) combining those data frames into one big data frame. (And suggests using `dplyr::bind_rows()` or `data.table::rbindlist` for combining data with differing columns.) – Gregor Thomas Feb 02 '23 at 16:46
  • The data are in the same directory. The data come from different countries however the majority of the variables are the same in all the datasets. And the desire is to have one single data instead of separate data for each country – Ekow_ababio Feb 02 '23 at 16:59

0 Answers0