Datumnotaties en extractiefuncties

R voor finance voor gevorderden

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Datumnotaties

# ISO 8601-standaard: jaar-maand-dag
as.Date("2017-01-28")
"2017-01-28"
# Alternatief: jaar/maand/dag
as.Date("2017/01/28")
"2017-01-28"
# Fout: maand/dag/jaar
as.Date("01/28/2017")
Error in charToDate(x) : 
  character string is not in 
  a standard unambiguous format
# Geef R het formaat expliciet op
as.Date("01/28/2017", format = "%m/%d/%Y")
"2017-01-28"
R voor finance voor gevorderden

Datumnotaties

Formaat Beschrijving
%d Dag van de maand (01-31)
%m Maand (01-12)
%y Jaar zonder eeuw (00-99)
%Y Jaar met eeuw (0-9999)
%b Afgekorte maandnaam
%B Volledige maandnaam
/ - , Veelgebruikte scheidingstekens
R voor finance voor gevorderden

Datumnotaties

Formaat Beschrijving
%d Dag van de maand (01-31)
%m Maand (01-12)
%y Jaar zonder eeuw (00-99)
%Y Jaar met eeuw (0-9999)
%b Afgekorte maandnaam
%B Volledige maandnaam
/ - , Veelgebruikte scheidingstekens
R voor finance voor gevorderden

Datumnotaties

Formaat Beschrijving
%d Dag van de maand (01-31)
%m Maand (01-12)
%y Jaar zonder eeuw (00-99)
%Y Jaar met eeuw (0-9999)
%b Afgekorte maandnaam
%B Volledige maandnaam
/ - , Veelgebruikte scheidingstekens
R voor finance voor gevorderden

Datumnotaties

Formaat Beschrijving
%d Dag van de maand (01-31)
%m Maand (01-12)
%y Jaar zonder eeuw (00-99)
%Y Jaar met eeuw (0-9999)
%b Afgekorte maandnaam
%B Volledige maandnaam
/ - , Veelgebruikte scheidingstekens
R voor finance voor gevorderden

Datumnotaties

Formaat Beschrijving
%d Dag van de maand (01-31)
%m Maand (01-12)
%y Jaar zonder eeuw (00-99)
%Y Jaar met eeuw (0-9999)
%b Afgekorte maandnaam
%B Volledige maandnaam
/ - , Veelgebruikte scheidingstekens
R voor finance voor gevorderden

Voorbeeld datumnotatie

Formaat Beschrijving
%d Dag van de maand (01-31)
%Y Jaar met eeuw (0-9999)
%B Volledige maandnaam
/ - , Veelgebruikte scheidingstekens
# Faillissement Lehman Brothers
# Complex formaat - wat gebruik je?
as.Date("September 15, 2008", format = "___")
as.Date("September 15, 2008", format = "%B %d, %Y")
"2008-09-15"
R voor finance voor gevorderden

Extractiefuncties

dates <- as.Date(c("2017-01-03", "2017-01-04"))
weekdays(dates)
"dinsdag"   "woensdag"
R voor finance voor gevorderden

Laten we oefenen!

R voor finance voor gevorderden

Preparing Video For Download...