I have a dataframe with some thousands of entries each, I've different province names. I need to substitute these names (which are repeated) for others.
Quick example, I have this column (I don't know how to show it like a column here):
**Provincia** Álava Álava Albacete Albacete Albacete ... Zaragoza Zaragoza
And I need to change for:
**Provincia** ALAVA_1 ALAVA_1 ALBACETE_1 ALBACETE_1 ALBACETE_1 ... ZGZ_1 ZGZ_1
I've tried the following:
old_names <- unique (df$Provincias)
Álava Albacete ... Zaragoza
new_names <- c ("ALAVA_1", "ALBACETE_1",... "ZGZ_1")
df$Provincias <- gsub (old_names, new_names, df$Provincias)
ALAVA_1 ALAVA_1 Albacete Albacete Albacete ... Zaragoza
1: In gsub (new_names, old_names, df$Provincias) : argument 'pattern' has length > 1 and only the first element will be used
2: In gsub (new_names, old_names, df$Provincias) : argument 'replacement' has length > 1 and only the first element will be used
So it only changes the first term (Álava for ALAVA_1) all the times, but it doesn't change the rest of Provincias
Of course I know that I can do this one by one, for the 52 provinces, but then I have more dataframes to do the same... I'm sure there's a better way.