Question: hello everyone,
I am trying to convert ENSEMBLE gene name to NCBI values; at the end of the process, I merged 2 data frames (one containing converted values and another one with log fold change, padj values assigned for each ensemble id). Unfortunately, some values like this:

ENSMUSG00000000562	c("11542"

rather than simply

ENSMUSG00000000562	11542

here the code

list <- read.csv(file='~/list.csv')
list <- as.character(list)

a <- sapply(list, function(x) exists(x, org.Mm.egENSEMBL2EG))
my.list <- list[a]

xx <- as.list(org.Mm.egENSEMBL2EG)
xx[my.list]

then

xx_table <- as.array(xx)
xx_table<- as.data.frame(xx_table)
xx_table<- as.matrix(xx_table)
write.csv(xx_table, file='~/ens2ncbi.csv')

ens2ncbi<- read.csv(file='~/ens2ncbi.csv')
ens2ncbi<-ens2ncbi[, 2:1]

merge.data <- merge(ens2ncbi, OTHER_dataframe, by="en")
write.csv(merge.data, file='~/ens2ncbi_merged.csv')

Answer: Those problematic Ensembl IDs are ones that have mappings to multiple Entrez (Refseq) IDs. You also make your situation difficult by converting your list to an array, then a data-frame, and then a matrix. You'll notice that these multiple mappings, based on the way that you've processed the data and just before your matrix conversion step, are separated by a comma in each entry. Using your code:

xx <- as.list(org.Mm.egENSEMBL2EG)
xx_table <- as.array(xx)
xx_table <- as.data.frame(xx_table)
tail(xx_table, 51)
xx_table
ENSMUSG00000090744 102642386
ENSMUSG00000095717 102642706, 102642868
ENSMUSG00000072915 102642717

Thus, the subsequent conversion of this to a data-matrix (which only allows numerical values) trips up because it sees the comma and doesn't know what to do with it. The `as.matrix` function neither gives a warning, but it should.

--------------------------------------

The most efficient way to convert between a list and a data-frame is with `do.call`, as you'll see in my code below:

xx <- as.list(org.Mm.egENSEMBL2EG)
xx_table <- do.call(rbind, lapply(xx, data.frame, stringsAsFactors=FALSE))
xx_table <- data.frame(rownames(xx_table), xx_table)

You'll then begin to see the issue:

tail(xx_table,55)
rownames.xx_table. X..i..
ENSMUSG00000094556 ENSMUSG00000094556 102641780
ENSMUSG00000095508 ENSMUSG00000095508 102641863
ENSMUSG00000103587 ENSMUSG00000103587 102642162
ENSMUSG00000090744 ENSMUSG00000090744 102642386
ENSMUSG00000095717.1 ENSMUSG00000095717.1 102642706
ENSMUSG00000095717.2 ENSMUSG00000095717.2 102642868
ENSMUSG00000072915 ENSMUSG00000072915 102642717

Here, ENSMUSG00000095717 has a mapping to 2 Entrez IDs and do.call (coupled with data.frame) has renamed the IDs to make them unique. We can tidy these up with `gsub` and then finish the remainder of the code:

xx_table[,1] <- gsub("\\.[0-9]*$", "", xx_table[,1])
write.csv(xx_table, "~/ens2ncbi.csv")
ens2ncbi <- read.csv(file="~/ens2ncbi.csv")
ens2ncbi <-ens2ncbi[, 3:2]
colnames(ens2ncbi) <- c("Entrez", "Ensembl")
head(ens2ncbi)
Entrez Ensembl
1 11287 ENSMUSG00000030359
2 11298 ENSMUSG00000020804
3 11302 ENSMUSG00000025375
4 11303 ENSMUSG00000015243
5 11304 ENSMUSG00000028125
6 11305 ENSMUSG00000026944

tail(ens2ncbi,52)
Entrez Ensembl
24186 102642386 ENSMUSG00000090744
24187 102642706 ENSMUSG00000095717
24188 102642868 ENSMUSG00000095717
24189 102642717 ENSMUSG00000072915
24190 102902673 ENSMUSG00000096370
24191 103164605 ENSMUSG00000102424
24192 104795665 ENSMUSG00000092765
24193 104795666 ENSMUSG00000093246

---------------------------

You'll just have to be wary of this going forward. Many of the merge functions will only take the first match that it finds, which may just be fine.

Kevin