[R-br] Criar uma coluna de lancamentos de pesca
Éder Comunello
comunello.eder em gmail.com
Quarta Maio 11 11:23:06 BRT 2016
Humberto, bom dia!
Segue uma uma sugestão, sem considerar que possa haver duplicidade...
### <code r>
df <- read.table(text=
"dia mes ano boat
9 1 2005 AGIOS.NIKOLAUS
10 1 2005 AGIOS.NIKOLAUS
11 1 2005 AGIOS.NIKOLAUS
12 1 2005 AGIOS.NIKOLAUS
13 1 2005 AGIOS.NIKOLAUS
9 1 2005 X
10 1 2005 X
11 1 2005 X
12 1 2005 Y
13 1 2005 Y", head=T, as.is=T)
df$lance <- NA
df
for (boat in unique(df$boat)) {
sel <- which(df$boat==boat)
df[sel, "lance"] <- 1:length(sel)
}
df
# dia mes ano boat lance
# 1 9 1 2005 AGIOS.NIKOLAUS 1
# 2 10 1 2005 AGIOS.NIKOLAUS 2
# 3 11 1 2005 AGIOS.NIKOLAUS 3
# 4 12 1 2005 AGIOS.NIKOLAUS 4
# 5 13 1 2005 AGIOS.NIKOLAUS 5
# 6 9 1 2005 X 1
# 7 10 1 2005 X 2
# 8 11 1 2005 X 3
# 9 12 1 2005 Y 1
# 10 13 1 2005 Y 2
### </code>
================================================
Éder Comunello
Agronomist (UEM), MSc in Environ. Sciences (UEM)
DSc in Agricultural Systems Engineering (USP/Esalq)
Brazilian Agricultural Research Corporation (Embrapa)
Dourados, MS, Brazil |<O>|
================================================
GEO, -22.2752, -54.8182, 408m
UTC-04:00 / DST: UTC-03:00
Em 11 de maio de 2016 09:37, Humberto Hazin <hhazin em gmail.com> escreveu:
> Olá pessoal,
>
>
>
> Estou precisando criar uma coluna chamada lances. Onde cada lance
> corresponde a um dia, mês, ano e barco conforme o exemplo abaixo:
>
>
>
> dia
>
> mes
>
> ano
>
> boat
>
> 9
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 10
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 11
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 12
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 13
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
>
>
>
>
> Eu gostaria que a tabela ficasse dessa forma aqui
>
>
>
> dia
>
> mes
>
> ano
>
> boat
>
> Lance
>
> 9
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 1
>
> 10
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 2
>
> 11
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 3
>
> 12
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 4
>
> 13
>
> 1
>
> 2005
>
> AGIOS.NIKOLAUS
>
> 5
>
>
>
>
>
> Agradeço desde já
>
>
>
> Humberto
>
>
>
>
>
>
>
>
>
> _______________________________________________
> R-br mailing list
> R-br em listas.c3sl.ufpr.br
> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
> código mínimo reproduzível.
>
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20160511/880665de/attachment.html>
Mais detalhes sobre a lista de discussão R-br