Formatos de data e funções extratoras

R Intermediário para Finanças

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Formatos de data

# Padrão ISO 8601: ano-mês-dia
as.Date("2017-01-28")
"2017-01-28"
# Forma alternativa: ano/mês/dia
as.Date("2017/01/28")
"2017-01-28"
# Falha: mês/dia/ano
as.Date("01/28/2017")
Error in charToDate(x) : 
  character string is not in 
  a standard unambiguous format
# Informe explicitamente o formato ao R
as.Date("01/28/2017", format = "%m/%d/%Y")
"2017-01-28"
R Intermediário para Finanças

Formatos de data

Format Description
%d Day of the month (01-31)
%m Month (01-12)
%y Year without century (00-99)
%Y Year with century (0-9999)
%b Abbreviated month name
%B Full month name
/ - , Common separators
R Intermediário para Finanças

Formatos de data

Format Description
%d Day of the month (01-31)
%m Month (01-12)
%y Year without century (00-99)
%Y Year with century (0-9999)
%b Abbreviated month name
%B Full month name
/ - , Common separators
R Intermediário para Finanças

Formatos de data

Format Description
%d Day of the month (01-31)
%m Month (01-12)
%y Year without century (00-99)
%Y Year with century (0-9999)
%b Abbreviated month name
%B Full month name
/ - , Common separators
R Intermediário para Finanças

Formatos de data

Format Description
%d Day of the month (01-31)
%m Month (01-12)
%y Year without century (00-99)
%Y Year with century (0-9999)
%b Abbreviated month name
%B Full month name
/ - , Common separators
R Intermediário para Finanças

Formatos de data

Format Description
%d Day of the month (01-31)
%m Month (01-12)
%y Year without century (00-99)
%Y Year with century (0-9999)
%b Abbreviated month name
%B Full month name
/ - , Common separators
R Intermediário para Finanças

Exemplo de formato de data

Format Description
%d Day of the month (01-31)
%Y Year with century (0-9999)
%B Full month name
/ - , Common separators
# Falência do Lehman Brothers
# Formato complexo - o que usar?
as.Date("September 15, 2008", format = "___")
as.Date("September 15, 2008", format = "%B %d, %Y")
"2008-09-15"
R Intermediário para Finanças

Funções extratoras

dates <- as.Date(c("2017-01-03", "2017-01-04"))
weekdays(dates)
"Tuesday"   "Wednesday"
R Intermediário para Finanças

Vamos praticar!

R Intermediário para Finanças

Preparing Video For Download...