I have the following df where two columns ara labeled with the same name:
dput(df_test)
structure(list(X = c("Gen", "ABCB1", "ABCG2", "CES1"), X.1 = c("Prioridad del gen",
"Candidato", "Candidato", "Candidato"), X.2 = c("Región codificante",
"2110", "1526", "3533"), X.3 = c("Categoría Reg. Codif.", "intron",
"intron", "intron"), X.4 = c("Alineamiento múltiple", "No", "No",
"No"), X.5 = c("Cromosoma", "7", "4", "16"), X.6 = c("Posición inicial",
"87153584", "89096060", "55855151"), X.7 = c("Posición final",
"87153585", "89096061", "55855151"), X.8 = c("Tamaño (pb)", "2",
"2", "1"), X.9 = c("Nº pb cob. ? 15X", "0", "1", "0"), X.10 = c("Nº pb cob. ? 15X",
"2", "1", "1"), X.11 = c("% pb cob. ? 15X", "0%", "50%", "0%"
), X.12 = c("Cobertura media", "3", "14,50", "0"), X.13 = c("Nº pb sin cubrir",
"0", "0", "1"), X.14 = c("Nº pb cob. [1-5]", "2", "0", "0"),
X.15 = c("Nº pb cob. [6-14]", "0", "1", "0"), X.16 = c("Nº pb cob. [15-29]",
"0", "1", "0"), X.17 = c("Nº pb cob. ? 30X", "0", "0", "0"
)), class = "data.frame", row.names = c(NA, -4L))
Because the first raw is empty in the original file, the real header becomes part of the df instead of being used as the header. Hence, I use row_to_names to move up the raw containing the names:
df1 <- read.delim("file", header = T) %>% row_to_names(row_number = 1)
Now I need to rename the columns "Nº pb cob. ? 15X" as "Nº pb cob. ≥ 15X" and " Nº pb cob. ≤ 15X", respectively. I've tried with:
clean_ rename_at clean_names() after row_to_names() and didn't change anything.
rename_vars and rename_at didn't work out either.
df1 <- rename_at(df1, 10, ~"Num pb cob. ≥ 15X") Error in
combine_names()
: ! Can't rename duplicate variables to{name}
. Runrlang::last_error()
to see where the error occurred.
Could any one give me some advice¿?
Thanks!!