<p>You need to think about whether to take the average for all probes belonging to one gene, or simply append the gene name to the probe id.</p>

<p>If it is simply adding a gene name, maybe try this below, note I am assuming that all your rownames of mat can be found in matched</p>

<pre><code># check whether all rownames are in matched
table(rownames(mat) %in% rownames(matched))
# rename the rows
tmp = paste(matched[match(rownames(mat),rownames(matched)),1],rownames(mat),sep="_")
rownames(mat) = tmp
</code></pre>

CC BY-SA 4.0
2019-10-10T12:45:12.537Z
2019-10-10T13:58:57.220Z
2019-10-10T13:58:57.220Z
StupidWolf
<p>There are actually two questions.</p>

<p>The first one is about the memory issue. I believe <code>merge</code> from <code>data.table</code> would solve that issue.</p>

<p>The second one would be aggregating or summarizing the identifiers. As @StupidWolf mentioned, you need to have a rule, summing them up, averaging them, ... For this second part one way is using <code>dplyr</code>:</p>

<pre><code>merged_data %&gt;%
  group_by(probe_colum) %&gt;%
  summarise_all(mean or sum or ...) %&gt;%
  mutate(new_column = paste(probe_column, gene_column, sep = "_"))
</code></pre>

<p>The same thing can be done faster with <code>data.table</code>:</p>

<pre><code>merged_data[, lapply(.SD, mean or sum or ..., na.rm=TRUE), by = probe_column ] [, new_column := paste(probe_column, gene_column, sep = "_"),]  
</code></pre>

<p><code>.SD</code> means subset of data and your subsets are your groups based on your probes.</p>

CC BY-SA 4.0
2019-10-10T13:28:27.377Z
hey @haci, what you proposed should work. Adding one column to the original expression matrix should not lead to memory issues. I think the problem might be coming from not being able to match the probe id to rownames of the matrix
StupidWolf
CC BY-SA 4.0
2019-10-10T13:12:40.827Z
2019-10-10T13:26:31.607Z
2019-10-10T13:26:31.607Z
haci
<p>I have a microarray gene expression matrix like this by weird gene IDs in rows. </p>

<pre><code>&gt; head(mat[1:10,1:5])

&gt; dim(mat)
[1] 39302    76
&gt;
</code></pre>

<p>There is matched gene symbol for each of these identifiers in another matrix </p>

<pre><code>&gt; 

&gt; dim(matched)
[1] 23107     1
&gt;
</code></pre>

<p>How I can have matched gene symbol with probe identifiers in the row names of my expression matrix please? The problem is, for one gene symbol we may 
I tried </p>

<pre><code>&gt; merged &lt;- merge(mat, matched) 
Error: cannot allocate vector of size 6.8 Gb
</code></pre>

<blockquote>
  <p><strong><em>EDITED</em></strong></p>
</blockquote>

<pre><code>tmp = paste(matched[rownames(mat)],rownames(mat),sep="_")
&gt; rownames(mat) = tmp
</code></pre>

<p><strong>EDITED</strong>  </p>

<p>This is my matrix after matching prob identifiers to gene symbol</p>

<pre><code>&gt; head(array[,1:10,1:5])
               GSM482796 GSM482797 GSM482798 GSM482799
1         OR2T6    0.0171   -0.1100   -0.0394   -0.0141
2          EBF1    0.1890    0.0222    0.0832    0.0459
3 DKFZp686D0972    1.9400    0.2530    0.3770    0.8310
4        ATP8B4   -0.1490    0.0690   -0.0637   -0.0527
5      NOTCH2NL    0.1540   -0.3880    0.2160   -0.0812
6        SPIRE1    0.2920    0.1690    0.5500    0.1430
</code></pre>

<p>but now for some genes I have several probes. For example for gene A I have several matched probes. So I have repetition for gene A. How I can take mean over the expression of repeated genes please and having an unique value?</p>

CC BY-SA 4.0
2019-10-18T11:24:15.337Z
It's not at all clear what format your data are in. Could you add `dput(head(matched))`?
alan ocallaghan
<r>
How I swap rownames in these data?
# How I swap rownames in these data?

(Asked by: username_0 on 2019-10-10)

I have a microarray gene expression matrix like this by weird gene IDs in rows. 
> head(mat[1:10,1:5])

> dim(mat)
[1] 39302    76
>

There is matched gene symbol for each of these identifiers in another matrix 
> 

> dim(matched)
[1] 23107     1
>

How I can have matched gene symbol with probe identifiers in the row names of my expression matrix please? The problem is, for one gene symbol we may 
I tried 
> merged <- merge(mat, matched) 
Error: cannot allocate vector of size 6.8 Gb


EDITED

tmp = paste(matched[rownames(mat)],rownames(mat),sep="_")
> rownames(mat) = tmp

EDITED 
This is my matrix after matching prob identifiers to gene symbol
> head(array[,1:10,1:5])
               GSM482796 GSM482797 GSM482798 GSM482799
1         OR2T6    0.0171   -0.1100   -0.0394   -0.0141
2          EBF1    0.1890    0.0222    0.0832    0.0459
3 DKFZp686D0972    1.9400    0.2530    0.3770    0.8310
4        ATP8B4   -0.1490    0.0690   -0.0637   -0.0527
5      NOTCH2NL    0.1540   -0.3880    0.2160   -0.0812
6        SPIRE1    0.2920    0.1690    0.5500    0.1430

but now for some genes I have several probes. For example for gene A I have several matched probes. So I have repetition for gene A. How I can take mean over the expression of repeated genes please and having an unique value?

**Tags:** r
> **Comments:**
> **username_1**: It's not at all clear what format your data are in. Could you add `dput(head(matched))`?  

---

## 2 answers

### Answer by username_2 on 2019-10-10. Score: 2 | Accepted answer

You need to think about whether to take the average for all probes belonging to one gene, or simply append the gene name to the probe id.
If it is simply adding a gene name, maybe try this below, note I am assuming that all your rownames of mat can be found in matched
# check whether all rownames are in matched
table(rownames(mat) %in% rownames(matched))
# rename the rows
tmp = paste(matched[match(rownames(mat),rownames(matched)),1],rownames(mat),sep="_")
rownames(mat) = tmp


---

### Answer by username_3 on 2019-10-10. Score: 3

There are actually two questions.
The first one is about the memory issue. I believe merge from data.table would solve that issue.
The second one would be aggregating or summarizing the identifiers. As @StupidWolf mentioned, you need to have a rule, summing them up, averaging them, ... For this second part one way is using dplyr:
merged_data %>%
  group_by(probe_colum) %>%
  summarise_all(mean or sum or ...) %>%
  mutate(new_column = paste(probe_column, gene_column, sep = "_"))

The same thing can be done faster with data.table:
merged_data[, lapply(.SD, mean or sum or ..., na.rm=TRUE), by = probe_column ] [, new_column := paste(probe_column, gene_column, sep = "_"),]  

.SD means subset of data and your subsets are your groups based on your probes.

> **Comments:**
> **username_2**: hey @haci, what you proposed should work. Adding one column to the original expression matrix should not lead to memory issues. I think the problem might be coming from not being able to match the probe id to rownames of the matrix  

---

