<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Wagner, bom dia!</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Tentei melhorar um pouco o script, tendo em mente os comentários do colega Cesar Rabak. Considerei apenas os sobrenomes de língua portuguesa, mas com um pouco de trabalho dá pra estender para outras línguas ("Alexander <u>von </u>Humboldt", "Johannes Diderik <u>van der</u> Waals", "Giuseppe <u>Della </u>Rosa", etc.)</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style=""><div class="gmail_default"><font face="monospace, monospace">### <code r></font></div><div class="gmail_default"><font face="monospace, monospace">names <- c("Antônio João dos Santos", "Antônio Souza Brás Filho",</font></div><div class="gmail_default"><font face="monospace, monospace"> "Bento Munhoz Rocha Souza", "Carlos Henrique Souza Sobrinho Neto", </font></div><div class="gmail_default"><font face="monospace, monospace"> "Damasceno de Souza", "Eustácio da Silva Lima", "Fábio Pereira", </font></div><div class="gmail_default"><font face="monospace, monospace"> "Gustavo de Araújo Junior"); names</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">composite <- c("Junior", "Júnior", "Filho", "Neto", "Sobrinho")</font></div><div class="gmail_default"><font face="monospace, monospace">composite <- paste(composite, collapse="|")</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">### Marcando nomes compostos com uso de hífen</font></div><div class="gmail_default"><font face="monospace, monospace">names2 <- names</font></div><div class="gmail_default"><font face="monospace, monospace">names2 <- gsub(paste0(" (", composite, ")"), "-\\1", names2)</font></div><div class="gmail_default"><font face="monospace, monospace">names2 <- gsub(" (d.?.) ", " \\1-", names2) </font></div><div class="gmail_default"><font face="monospace, monospace">names2</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">split <- strsplit(names2, ' ')</font></div><div class="gmail_default"><font face="monospace, monospace">terms <- unlist(lapply(split, length)); terms</font></div><div class="gmail_default"><font face="monospace, monospace">n <- length(terms)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">sapply(1:n, function(x) split[[x]][1]) # Primeiro</font></div><div class="gmail_default"><font face="monospace, monospace">sapply(1:n, function(x) split[[x]][terms[x]]) # Último</font></div><div class="gmail_default"><font face="monospace, monospace">sapply(1:n, function(x) paste(split[[x]][-c(1,terms[x])], collapse=" ")) # Intermediários</font></div><div class="gmail_default"><font face="monospace, monospace">sapply(1:n, function(x) (split[[x]][-c(1,terms[x])])[1]) # Segundo nome...</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">### Removendo os hífens</font></div><div class="gmail_default"><font face="monospace, monospace">split2 <- lapply(split, function(x) gsub("-", " ", x))</font></div><div class="gmail_default"><font face="monospace, monospace">sapply(1:n, function(x) split2[[x]][terms[x]]) # Último</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">### Removendo c("da", "de", "dos")</font></div><div class="gmail_default"><font face="monospace, monospace">split3 <- lapply(split2, function(x) gsub("^d.?. ", "", x)) </font></div><div class="gmail_default"><font face="monospace, monospace">sapply(1:n, function(x) split3[[x]][terms[x]]) # Último</font></div><div class="gmail_default"><font face="monospace, monospace">### </code></font></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font face="arial, helvetica, sans-serif" style="font-size:small"><div style="font-family:'trebuchet ms',sans-serif;display:inline"></div></font><font face="arial, helvetica, sans-serif" style="font-size:12.8px"><span style="font-size:small">================================================</span><br>Éder Comunello</font><div style="font-size:12.8px"><span style="font-family:arial,helvetica,sans-serif">Agronomist (UEM), MSc in Environ. Sciences (UEM)</span><font face="arial, helvetica, sans-serif"><br></font></div><div style="font-size:12.8px"><div style="font-size:small"><span style="font-family:arial,helvetica,sans-serif">DSc in Agricultural Systems Engineering (USP/Esalq)</span><br></div><div><span style="font-size:small">Brazilian Agricultural Research Corporation (</span><font face="arial, helvetica, sans-serif" style="font-size:small">Embrapa)</font></div><div><div><font face="arial, helvetica, sans-serif" style="font-size:small">Dourados, MS, Brazil </font><font face="arial, helvetica, sans-serif" size="2">|<O>|</font></div><div style="font-size:small"><span style="font-family:arial,helvetica,sans-serif">================================================</span><br></div></div></div><div style="font-size:small"><font face="arial, helvetica, sans-serif">GEO, </font>-22.2752, -54.8182, 408m<span style="font-family:arial,helvetica,sans-serif"><br></span></div><div style="font-size:12.8px"><span style="font-size:small;font-family:arial,helvetica,sans-serif">UTC-04:00 / DST: UTC-03:00</span></div><div><div><div><br></div><div><br></div></div><div style="font-size:small"><br></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote"><br></div></div></div>