0

I have a gene expression data set (myfirst_df) that has 259 columns (samples) and also I have another data set (mysecond_df) that include 100 rows. I would like to select and extract these 100 rows from 259 samples in the first data set. All 100 samples in mysecond_df are in 259 samples in myfirst_df. I need to guide at the code level for doing this task. I write my code in the R language.

Myfirst_df

    sample1    sample2      sample3    sample4   sample5 … sample259

 gene1
 gene2 
  .
  .
  .
Gene50000

mysecond_df

        col1       col2      col3    col4     col5   ….. col40
  sample1
  sample4
  sample9
  sample13
   .
   .
  sample100

My Favorite dataset

     sample1    sample4   sample9    sample13   … sample100
  gene1
  gene2 
   .
   .
   .
Gene50000
Cettt
  • 11,460
  • 7
  • 35
  • 58
Mohammad
  • 103
  • 6
  • Hi there! I'm afraid it's almost impossible to help without a reproducible example to try with, take a look at this post [how to make a great r reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and see if you can edit your question to help others help you – DS_UNI Apr 19 '19 at 11:23
  • Hi Mohmmad, If you can provide the key references between these two datasets, and also give details of their structure proper name of their variables, that would help to find the solution, you looking for – nandal Apr 19 '19 at 11:25

1 Answers1

1

try something like this:

mysamples <- mysecond_df[,1] 

or if sample1, sample4,.. are row.names then

mysamples <- rownames(mysecond_df)

Afterwards

Myfirst_df[, mysamples]

should give the desired result.

Cettt
  • 11,460
  • 7
  • 35
  • 58