What is the best way to do a descriptive analysis of birth dates in R?

3

I have in my data frame a column of birth dates that are in the English model, but I do not know how to analyze this descriptively nor what resources to use from R.

Should I use a bar chart or a histogram? How would the R understand what dates are? I tried to take the risk by doing this:

x = as.Date(rehab.1$Data.Nascimento)

hist(x, main = "Data de Nascimento", breaks = "years",axes = TRUE, xlab = "data", ylab = "Frequência Absoluta", col = "green")

But what came out was not cool:

    
asked by anonymous 24.03.2016 / 18:12

1 answer

3

Your code has some problems:

  • The as.Date function assumes the date is in Y / m / d format, and its date is in the m / d / Y format. Switch the first call to x <- as.Date(rehab.1$Data.Nascimento, "%m/%d/%Y")
  • What information do you want to display on your histogram? How many people were born each year? In each month? Depending on what you want, you will use different methods.

For example, to show the number of births per year, you can use the method you used (hist, with breaks="years"), as in the code below.

randomDates <- function(N, st = "1/1/1920", et = "12/31/2015") {
    st <- as.POSIXlt(as.Date(st, "%m/%d/%Y"))
    et <- as.POSIXlt(as.Date(et, "%m/%d/%Y"))
    dt <- as.numeric(difftime(et, st, unit = "sec"))
    ev <- runif(N, 0, dt)
    st + ev
}
x <- randomDates(1000)
hist(x, freq = TRUE,
     breaks = "years", col = "green",
     xlab = "ano", "ylab" = "Frequencia",
     main = "Ano de nascimento")
    
24.03.2016 / 19:56