Hi R-Users,
I want to manipulate some strings in the following way. I have the
following vector with spanish municipalities:
municipios<-c("Allande", "Aller", "Amieva",
"Avil?s", "Belmonte de
Miranda",
"Dega?a", "Franco (El)", "Gij?n",
"Goz?n", "Grado", "Grandas de Salime",
"Quir?s", "Regueras (Las)", "Ribadedeva",
"Ribadesella", "Ribera de
Arriba")
The problem is: some names have an article ("Franco (El)",
"Regueras
(Las)"). Others don't. I want to do the following conversion:
"Regueras (Las)"---> "Las Regueras"
That is: I want to loop through the names, look whether they have a
postponed article, extract and delete this article and put it in front
of the rest of the name.
Any hints? Thanks in advance.
--
:: Igor Sosa Mayor :: joseleopoldo1792 at gmail.com ::
:: GnuPG: 0x69804897 :: http://www.gnupg.org/ ::
I have to add some clarification: there are ONLY 4 articles (el,la,los,las) and the structure is always the same: NAMEOFMUNICIPALITY (El) NAMEOFMUNICIPALITY (La) etc. On Tue, Mar 13, 2012 at 10:42:54AM +0100, Igor Sosa Mayor wrote:> Hi R-Users, > > I want to manipulate some strings in the following way. I have the > following vector with spanish municipalities: > > municipios<-c("Allande", "Aller", "Amieva", "Avil?s", "Belmonte de > Miranda", > "Dega?a", "Franco (El)", "Gij?n", "Goz?n", "Grado", "Grandas de Salime", > "Quir?s", "Regueras (Las)", "Ribadedeva", "Ribadesella", "Ribera de > Arriba") > > The problem is: some names have an article ("Franco (El)", "Regueras > (Las)"). Others don't. I want to do the following conversion: > > "Regueras (Las)"---> "Las Regueras" > > That is: I want to loop through the names, look whether they have a > postponed article, extract and delete this article and put it in front > of the rest of the name. > > Any hints? Thanks in advance. > > -- > :: Igor Sosa Mayor :: joseleopoldo1792 at gmail.com :: > :: GnuPG: 0x69804897 :: http://www.gnupg.org/ ::-- :: Igor Sosa Mayor :: joseleopoldo1792 at gmail.com :: :: GnuPG: 0x69804897 :: http://www.gnupg.org/ ::
On 13-03-2012, at 10:42, Igor Sosa Mayor wrote:> Hi R-Users, > > I want to manipulate some strings in the following way. I have the > following vector with spanish municipalities: > > municipios<-c("Allande", "Aller", "Amieva", "Avil?s", "Belmonte de > Miranda", > "Dega?a", "Franco (El)", "Gij?n", "Goz?n", "Grado", "Grandas de Salime", > "Quir?s", "Regueras (Las)", "Ribadedeva", "Ribadesella", "Ribera de > Arriba") > > The problem is: some names have an article ("Franco (El)", "Regueras > (Las)"). Others don't. I want to do the following conversion: > > "Regueras (Las)"---> "Las Regueras" > > That is: I want to loop through the names, look whether they have a > postponed article, extract and delete this article and put it in front > of the rest of the name. > > Any hints? Thanks in advance.gsub("([^\\s]+)\\s*(\\()(.*)(\\))","\\3 \\1", municipios, perl=TRUE) Berend