I think you can then use merge() to merge them back together

n<- merge(n, df, by.x = c("m.values"), by.y = c("Start"), all.x = F, all.y = F)

also see ?aggregate for a more efficient solution.

HTH, Si.

----- Original Message ----- From: "Schönemann, Rene" <rschoenem...@railways.tu-berlin.de>
To: <R-help@r-project.org>
Sent: Thursday, June 18, 2009 1:37 PM
Subject: [R] filtering number of values in a data frame


Dear list,

given is the following data frame df():

       Number           Place               Start                 End
1 218024740787 HHO     5   263 2008-01-02 00:21:14 2008-01-03 15:25:16
2 218024740787 HHO     5   263 2008-01-02 00:21:14 2008-01-02 00:21:14
3 318039091794 HHO     5   263 2008-01-02 00:21:14 2008-01-02 13:22:54
4 318039091794 HHO     5   263 2008-01-02 00:21:14 2008-01-02 00:21:14
5 318039379900 HHO     1   104 2008-01-02 06:45:01 2008-01-02 09:15:23

Now, I want to count the number of equal values of column "Start" but I also want the other columns to be preserved.

Using:

rle(as.character(df$Start)) -> m
n <- data.frame(m$values, m$lengths)

produces a list of items according to their frequency of the Start point:

             m.values m.lengths
1 2008-01-02 00:21:14         4
2 2008-01-02 06:45:01         1


I want now also other columns to be in this new data frame. It should look like that:

         Number           Place           m.values  m.lengths
1 218024740787 HHO     5   263 2008-01-02 00:21:14         4
2 318039379900 HHO     1   104 2008-01-02 06:45:01         1


Does anybody can help me with this?

Thanking you in advance!

René Schönemann

--
______________________________________________________

Technische Universität Berlin
Institut für Land- und Seeverkehr
Fachgebiet Schienenfahrwege und Bahnbetrieb
Prof. Dr.-Ing. habil. Jürgen Siegmann

Post        Sekretariat SG 18
           Salzufer 17-19
           D-10587 Berlin

Telefon     +49 (0)30 314 - 23 314

Internet    http://www.railways.tu-berlin.de
______________________________________________________

Dipl.-Verk.wirtsch. René Schönemann
- Wissenschaftlicher Mitarbeiter -

Telefon     +49 (0)30 314 - 22 710
Telefax     +49 (0)30 314 - 25 530

E-Mail      rschoenem...@railways.tu-berlin.de
______________________________________________________

Technische Universität Berlin
Körperschaft öffentlichen Rechts

Präsident   Prof. Dr. Kurt Kutzler

______________________________________________
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.



______________________________________________
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