mercredi 17 mars 2021

iterate over rows in dataframe, and if a value is > #, output a different row in the same column

Imagine I have a dataframe of 100 columns that represent test subjects and 201 rows. The first row contains an ID that tells what group a test subject came from, the other rows are a measurement of gene expression. I would like to row by row and test each of the 200 values for the gene, measuring whether they were >= 5. If they are not, I would like to output the id in row1 corresponding to the low value

      subj1  subj2  subj3 ...
group  Dis    CNT   Dis
gene1   12     0     10
gene2   4      3     5
gene3   100   105    99

So here the output would be

gene1 CNT 
gene2 Dis, CNT
Gene3

Or even better, if it could output a running tally of the missingness in the groups:

       Dis CNT 
gene1  0    1
gene2  1    1
gene3  0    0

Im still pretty new to R, but I would like to resist the temptation to go and write this in perl. I feel like the task should be pretty siple. any assistance would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire