text: user15996: I have a data frame that I want to switch its row names from EnsembleID (GENEID) to gene symbol (SYMBOL). When I try to switch, I get this error:
  Error in `.rowNamesDF<-`(x, value = value) : 
    duplicate 'row.names' are not allowed
  In addition: Warning message:
   Error in `.rowNamesDF<-`(x, value = value) : 
    duplicate 'row.names' are not allowed 
  
  The code I'm using works for other similar data frames. Only this one is giving me trouble. There are no duplicates in the row names, I checked, so the source of this error is strange.
  This is the code:
  GetSymbols <- function(df) {   # Switch from geneID format to Symbol format
    
    ensembl.genes = as.vector(rownames(df))
    geneIDs = ensembldb::select(EnsDb.Hsapiens.v86, keys= ensembl.genes, keytype = "GENEID", columns = c("SYMBOL","GENEID"))
    dupli = duplicated(geneIDs$GENEID)
    geneIDs = geneIDs[!dupli,]
    rownames(geneIDs) = geneIDs$GENEID
    rownames(df) = geneIDs$SYMBOL
    return(df)
    
  }
  
  #Calling the function:
   df = GetSymbols(df)
  
  A sample of the dataframe:
  structure(list(logFC = c(0.362414024114299, 0.270660335317552, 
  0.250197714648158, 0.355106754020497, 0.860436247608723, 0.331838240496886, 
  0.642000001979217, -0.506238094622956, 0.199130048525963, 0.226010606161764, 
  -0.300273572714138, 0.763447672404514, -0.282220097838676, 0.686284440644756, 
  0.209266959343866, 0.201216572039244, 0.467207891400503, 0.207476905368996, 
  0.548263917432251, 0.582095719576479, 0.167369145307915, -0.239886539805618, 
  -0.133088162158502, 0.432528267703316, -0.232843401197013), AveExpr = c(2.63663927914016, 
  6.23730774047258, 6.74130527553022, 6.51256660562955, 3.51386518575641, 
  0.962682352871946, 3.60110717340049, -1.07537043066235, 4.55672701732791, 
  3.96125159652725, 1.20473881401599, 1.72955742088622, 2.10495435034315, 
  2.95446094011986, 4.31205976523475, 4.85412008885978, 4.09171246258306, 
  3.94681319329962, 6.27193781389662, 0.936821016422818, 7.97270280545117, 
  2.4470079966345, 5.75991260844846, 3.84225682530045, 3.35515997418382
  ), t = c(5.15993300980101, 4.74644046948475, 4.67895886939685, 
  4.65270476519835, 4.39369295809775, 4.51083389626156, 4.20489542862464, 
  -4.49987927160777, 4.1096966271885, 4.03273843222089, -4.09143780518073, 
  4.07713970281633, -3.99157698713235, 3.97814493972727, 3.94402861982903, 
  3.92673590933521, 3.92436825669156, 3.90538427413924, 3.89364498564491, 
  3.93360332510695, 3.80233390398449, -3.76935782400013, -3.7013905266149, 
  3.68313224298669, -3.68114307289328), P.Value = c(4.50582660244125e-07, 
  3.21245260466636e-06, 4.37260426507432e-06, 4.92523952290176e-06, 
  1.54869545509172e-05, 9.2842399715271e-06, 3.45373717288344e-05, 
  9.74370585569957e-06, 5.12014322967072e-05, 7.00192255628614e-05, 
  5.51721193906694e-05, 5.84844087520547e-05, 8.26184479488647e-05, 
  8.71763749953859e-05, 9.9850615705057e-05, 0.000106924308803713, 
  0.000107929018751166, 0.000116314737750083, 0.000121805424073131, 
  0.000104060063751203, 0.000173710084683786, 0.000197140244520663, 
  0.000255164374909145, 0.000273300166932535, 0.000275347732934516
  ), adj.P.Val = c(0.00727510763230165, 0.0198807293341929, 0.0198807293341929, 
  0.0198807293341929, 0.0357217668827299, 0.0262203124576875, 0.06970505049172, 
  0.0262203124576875, 0.0858444785191522, 0.09421086799483, 0.0858444785191522, 
  0.0858444785191522, 0.0968123298197961, 0.0968123298197961, 0.0968123298197961, 
  0.0968123298197961, 0.0968123298197961, 0.098333518854239, 0.098333518854239, 
  0.0968123298197961, 0.130401412989609, 0.138392451653505, 0.150726778618736, 
  0.150726778618736, 0.150726778618736), B = c(5.59649208873277, 
  4.23844568248881, 3.95926511142815, 3.85011503575047, 2.70095619489428, 
  2.52151007226572, 2.02920447371096, 1.82077681362955, 1.73104697407381, 
  1.44381690648743, 1.32264026808754, 1.26349133643967, 1.17476645994761, 
  1.17423988785926, 1.13844103561967, 1.07813935334313, 1.06670248721183, 
  1.0004861785984, 0.949862540556422, 0.634079467108277, 0.620590447127368, 
  0.489071423128816, 0.29054426889472, 0.254833988789798, 0.246174538031329
  )), row.names = c("ENSG00000188938", "ENSG00000182768", "ENSG00000174579", 
  "ENSG00000119523", "ENSG00000271798", "ENSG00000204923", "ENSG00000281910", 
  "ENSG00000271092", "ENSG00000153767", "ENSG00000116903", "ENSG00000168101", 
  "ENSG00000206834", "ENSG00000180035", "ENSG00000251733", "ENSG00000058729", 
  "ENSG00000132467", "ENSG00000212464", "ENSG00000115561", "ENSG00000230669", 
  "ENSG00000206612", "ENSG00000275272", "ENSG00000162139", "ENSG00000143889", 
  "ENSG00000207233", "ENSG00000119878"), class = "data.frame")
  
  
  user15996: I found an answer shortly after posting this question:
  ensembl.genes <- rownames(df)
  geneIDs <- ensembldb::select(EnsDb.Hsapiens.v86, keys= ensembl.genes, keytype = "GENEID", columns = c("SYMBOL","GENEID"))
  dupli = duplicated(geneIDs$SYMBOL)
  geneIDs = geneIDs[!dupli,]
  ind = intersect(rownames(df), geneIDs$GENEID)
  df = df[ind,]
  rownames(df) = geneIDs$SYMBOL
  
  
original_text: 15996: <p>I have a data frame that I want to switch its row names from EnsembleID (GENEID) to gene symbol (SYMBOL). When I try to switch, I get this error:</p>
  <pre><code>Error in `.rowNamesDF&lt;-`(x, value = value) : 
    duplicate 'row.names' are not allowed
  In addition: Warning message:
   Error in `.rowNamesDF&lt;-`(x, value = value) : 
    duplicate 'row.names' are not allowed 
  </code></pre>
  <p>The code I'm using works for other similar data frames. Only this one is giving me trouble. There are no duplicates in the row names, I checked, so the source of this error is strange.</p>
  <p>This is the code:</p>
  <pre><code>GetSymbols &lt;- function(df) {   # Switch from geneID format to Symbol format
    
    ensembl.genes = as.vector(rownames(df))
    geneIDs = ensembldb::select(EnsDb.Hsapiens.v86, keys= ensembl.genes, keytype = &quot;GENEID&quot;, columns = c(&quot;SYMBOL&quot;,&quot;GENEID&quot;))
    dupli = duplicated(geneIDs<span class="math-container">$GENEID)
    geneIDs = geneIDs[!dupli,]
    rownames(geneIDs) = geneIDs$</span>GENEID
    rownames(df) = geneIDs$SYMBOL
    return(df)
    
  }
  
  #Calling the function:
   df = GetSymbols(df)
  </code></pre>
  <h4>A sample of the dataframe:</h4>
  <pre><code>structure(list(logFC = c(0.362414024114299, 0.270660335317552, 
  0.250197714648158, 0.355106754020497, 0.860436247608723, 0.331838240496886, 
  0.642000001979217, -0.506238094622956, 0.199130048525963, 0.226010606161764, 
  -0.300273572714138, 0.763447672404514, -0.282220097838676, 0.686284440644756, 
  0.209266959343866, 0.201216572039244, 0.467207891400503, 0.207476905368996, 
  0.548263917432251, 0.582095719576479, 0.167369145307915, -0.239886539805618, 
  -0.133088162158502, 0.432528267703316, -0.232843401197013), AveExpr = c(2.63663927914016, 
  6.23730774047258, 6.74130527553022, 6.51256660562955, 3.51386518575641, 
  0.962682352871946, 3.60110717340049, -1.07537043066235, 4.55672701732791, 
  3.96125159652725, 1.20473881401599, 1.72955742088622, 2.10495435034315, 
  2.95446094011986, 4.31205976523475, 4.85412008885978, 4.09171246258306, 
  3.94681319329962, 6.27193781389662, 0.936821016422818, 7.97270280545117, 
  2.4470079966345, 5.75991260844846, 3.84225682530045, 3.35515997418382
  ), t = c(5.15993300980101, 4.74644046948475, 4.67895886939685, 
  4.65270476519835, 4.39369295809775, 4.51083389626156, 4.20489542862464, 
  -4.49987927160777, 4.1096966271885, 4.03273843222089, -4.09143780518073, 
  4.07713970281633, -3.99157698713235, 3.97814493972727, 3.94402861982903, 
  3.92673590933521, 3.92436825669156, 3.90538427413924, 3.89364498564491, 
  3.93360332510695, 3.80233390398449, -3.76935782400013, -3.7013905266149, 
  3.68313224298669, -3.68114307289328), P.Value = c(4.50582660244125e-07, 
  3.21245260466636e-06, 4.37260426507432e-06, 4.92523952290176e-06, 
  1.54869545509172e-05, 9.2842399715271e-06, 3.45373717288344e-05, 
  9.74370585569957e-06, 5.12014322967072e-05, 7.00192255628614e-05, 
  5.51721193906694e-05, 5.84844087520547e-05, 8.26184479488647e-05, 
  8.71763749953859e-05, 9.9850615705057e-05, 0.000106924308803713, 
  0.000107929018751166, 0.000116314737750083, 0.000121805424073131, 
  0.000104060063751203, 0.000173710084683786, 0.000197140244520663, 
  0.000255164374909145, 0.000273300166932535, 0.000275347732934516
  ), adj.P.Val = c(0.00727510763230165, 0.0198807293341929, 0.0198807293341929, 
  0.0198807293341929, 0.0357217668827299, 0.0262203124576875, 0.06970505049172, 
  0.0262203124576875, 0.0858444785191522, 0.09421086799483, 0.0858444785191522, 
  0.0858444785191522, 0.0968123298197961, 0.0968123298197961, 0.0968123298197961, 
  0.0968123298197961, 0.0968123298197961, 0.098333518854239, 0.098333518854239, 
  0.0968123298197961, 0.130401412989609, 0.138392451653505, 0.150726778618736, 
  0.150726778618736, 0.150726778618736), B = c(5.59649208873277, 
  4.23844568248881, 3.95926511142815, 3.85011503575047, 2.70095619489428, 
  2.52151007226572, 2.02920447371096, 1.82077681362955, 1.73104697407381, 
  1.44381690648743, 1.32264026808754, 1.26349133643967, 1.17476645994761, 
  1.17423988785926, 1.13844103561967, 1.07813935334313, 1.06670248721183, 
  1.0004861785984, 0.949862540556422, 0.634079467108277, 0.620590447127368, 
  0.489071423128816, 0.29054426889472, 0.254833988789798, 0.246174538031329
  )), row.names = c(&quot;ENSG00000188938&quot;, &quot;ENSG00000182768&quot;, &quot;ENSG00000174579&quot;, 
  &quot;ENSG00000119523&quot;, &quot;ENSG00000271798&quot;, &quot;ENSG00000204923&quot;, &quot;ENSG00000281910&quot;, 
  &quot;ENSG00000271092&quot;, &quot;ENSG00000153767&quot;, &quot;ENSG00000116903&quot;, &quot;ENSG00000168101&quot;, 
  &quot;ENSG00000206834&quot;, &quot;ENSG00000180035&quot;, &quot;ENSG00000251733&quot;, &quot;ENSG00000058729&quot;, 
  &quot;ENSG00000132467&quot;, &quot;ENSG00000212464&quot;, &quot;ENSG00000115561&quot;, &quot;ENSG00000230669&quot;, 
  &quot;ENSG00000206612&quot;, &quot;ENSG00000275272&quot;, &quot;ENSG00000162139&quot;, &quot;ENSG00000143889&quot;, 
  &quot;ENSG00000207233&quot;, &quot;ENSG00000119878&quot;), class = &quot;data.frame&quot;)
  </code></pre>
   15996: <p>I found an answer shortly after posting this question:</p>
  <pre><code>ensembl.genes &lt;- rownames(df)
  geneIDs &lt;- ensembldb::select(EnsDb.Hsapiens.v86, keys= ensembl.genes, keytype = &quot;GENEID&quot;, columns = c(&quot;SYMBOL&quot;,&quot;GENEID&quot;))
  dupli = duplicated(geneIDs<span class="math-container">$SYMBOL)
  geneIDs = geneIDs[!dupli,]
  ind = intersect(rownames(df), geneIDs$</span>GENEID)
  df = df[ind,]
  rownames(df) = geneIDs$SYMBOL
  </code></pre>
  