I have 2 data sets I am working with in R. In the first, I have multiple txt files with expression values for different genes. Each file has the same column and row names.
gene_ID expression_value
gene_1 expression_value_1
... ...
In the second, I have a master chart (csv file) which associates the name of each txt file with a patient ID.
name_txt_file patient_ID
txt_file_1 patient_1
I am trying to create a master file with the gene expression values for all patients for each gene.
patient_ID gene_1 gene_2 ...
patient_1 expression_value_1 expression_value_2
patient_2 expression_value_x expression_value_y
So far I have created an empty data frame with the correct column and row names, but I do not know how to associate the name of each txt file with a patient ID from the master chart (csv file) and fill in the expression values for this empty data frame. I am assuming some sort of for loop function could be used, but do not know how to write functions which will associate the data in a file with a patient ID based on the file's name. Any help would be greatly appreciated.