[R] Frequency of Data

james.holtman@convergys.com james.holtman at convergys.com
Wed Feb 2 21:08:22 CET 2005





Try this using strsplit and table:

> dates <- c('29.02.1997','15.02.2001','15.02.2001','23.12.2002')

> x.1 <- do.call('rbind',strsplit(dates,'\\.'))
> x.1
     [,1] [,2] [,3]
[1,] "29" "02" "1997"
[2,] "15" "02" "2001"
[3,] "15" "02" "2001"
[4,] "23" "12" "2002"
> class(x.1) <- 'integer'
> x.1
     [,1] [,2] [,3]
[1,]   29    2 1997
[2,]   15    2 2001
[3,]   15    2 2001
[4,]   23   12 2002

> table(list(x.1[,2], x.1[,3]))

    .2
.1   1997 2001 2002
  2  1    2    0
  12 0    0    1
>
__________________________________________________________
James Holtman        "What is the problem you are trying to solve?"
Executive Technical Consultant  --  Office of Technology, Convergys
james.holtman at convergys.com
+1 (513) 723-2929


                                                                                                                                                     
                      "Carsten Steinhoff"                                                                                                            
                      <carsten.steinhoff at stud.uni-goe        To:       <r-help at stat.math.ethz.ch>                                                    
                      ttingen.de>                            cc:                                                                                     
                      Sent by:                               Subject:  [R] Frequency of Data                                                         
                      r-help-bounces at stat.math.ethz.c                                                                                                
                      h                                                                                                                              
                                                                                                                                                     
                                                                                                                                                     
                      02/02/2005 14:44                                                                                                               
                                                                                                                                                     
                                                                                                                                                     




Hello,

just another problem in R, maybe it's simple to solve for you. I didn't
find
a solution up to now, but I'm convinced that I'm not the only one who
has/had a similar problem. Maybe there's a ready-made function in R?

The prob:

I've imported a CSV-file into R with 1000 dates of an observed event
(there's only information of the date. When there happend no event the date
is not recorded, when there have been two events it's recordet twice). Now
I
want to COUNT the frequency of events in every month or year.

The CSV-data is structured as:

date
25.02.2003
29.07.1997
...

My desired output would be a matrix with n rows for the years and m columns
for the month.

How could a solution look like ? If the format is no matrix it doesn't
matter. Importend is the extraction of frequency from my data.

Thanks for all reply,

Carsten

             [[alternative HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list