R script for merging multiple excel files with header,and for Blast

Dear All,
I am pretty new working fully with R, I am trying to Blast my desired gene , to pick up hits(5/10)first i need to merge my metadata files in R.
can you point me in the right direction?
Thank you

Hi @JoyA you could put a reproducible example of data set?

check this:

because you could load the data sets and with a simple left_join merge this ones by a specific id column.

2 Likes

I've recently done something similar. I have a folder containing many files of data. Each file follows a standard naming convention. I was able to read each of the files with one command; very little copy and paste. After the data was loaded in the environment I could join them together and begin my analysis. Something similar to this might work for you. Good luck.

library(tidyverse)
library(janitor)

# collect file names for function
filenames <- list.files(
  path = "path-to-your-files",
  pattern = "name-pattern-to-identify-your-files",
  full.names = TRUE
)

# collect file names to name environment objects
filenames_short <- list.files(
  path = "path-to-your-files",
  pattern = "name-pattern-to-identify-your-files",
  full.names = FALSE
)

# write function
func_read <- function(x, y) { # x = filename for sas; y = object name
  tmp <- read_csv(x) %>%
    clean_names() %>%
    mutate(filename = as.character(x)) # create new variable of file name
  assign(y, tmp, envir = .GlobalEnv) # create data objects
}

# iteratively call function for each desired file
map2(
  .x = filenames,
  .y = filenames_short,
  .f = ~ func_read(.x, .y)
)

# inspect; which data objects were created?
ls(pattern = "name-pattern-to-identify-your-files")

# combine to one data set
data_joined <- mget(ls(pattern = "name-pattern-to-identify-your-file")) %>%
  bind_rows()

# inspect
glimpse(data_joined)
2 Likes

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.