Dear R users,
I have got the following data frame, called my_df:

   gender day_birth month_birth year_birth labour
1           F             22                  10           2001          1
2           M            29                  10           2001          2
3           M              1                   11          2001          1
4           F               3                  11           2001          1
5           M              3                  11           2001          2
6           F              4                   11           2001          1
7           F              4                   11           2001          2
8           F              5                   12           2001          2
9           M           22                   14           2001          2
10         F           29                   13           2001          2
...

I need to count data in different ways:

1. count the births for each day (having 0 when necessary) independently from 
the value of the "labour" column

2. count the births for each day (having 0 when necessary), divided by the 
value of "labour" (which can have two valuers, 1 or 2)

3. count the births for each day of all the years (i.e. the 22nd of October of 
all the years present in the data frame) independently from the value of 
"labour"

4. count the births for each day of all the years (i.e. the 22nd of October of 
all the years present in the data frame), divided by the value of "labour"

I tried with the command

table(my_df$year_birth, my_df$month_birth, my_df$day_birth)

which satisfies (partially) question numer 1 (I am not able to have 0 in the 
not available days).

Is there a smart way to do that without invoking too many loops?

thank you for your help
Stefano Sofia


AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
è il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell’art. 6 della  DGR n. 1394/2008 si segnala che, in caso di necessità ed 
urgenza, la risposta al presente messaggio di posta elettronica può essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to