Re: [R] How to preserve date format while aggregating
This is completely wrong: min _is_ defined for date-times: min(.leap.seconds) [1] 1972-07-01 01:00:00 BST Please do study the posting guide and do your homework before posting: you seem unaware of what the POSIXct class is, so ?DateTimeClasses is one place you need to start. And methods(Summary) [1] Summary.data.frame Summary.DateSummary.difftime [4] Summary.factor Summary.numeric_version Summary.POSIXct [7] Summary.POSIXlt so ?Summary is another. On Mon, 8 Sep 2008, Adam D. I. Kramer wrote: Hi Erich, Since min() is defined for numbers and not dates, the problem is in the min() function. min() is converting from date format to number format. Your best bet is to make this conversion explicit...such that it is reversable. So, convert the date into UTC, then UTC to seconds since epoch, then take the minimum, then convert back to UTC time. This sounds like a pain...but that's basically what a version of min() designed to work with dates would do. The reason this is a pain is basically due to timezones: Consider a comparison between x = 3:54 PM September 8 in California (right now where I am) and y = 12:54 AM September 9 in Zurich (right now where you are). Is it earlier here than there? Yes, because it's Sept 8 to your Sept 9. Is it earlier there than here? Yes, because your day started 56 minutes ago, mine over 15 hours ago. Is it the same time here than there? Yes, because our UTC times are equal. So it's not clear what min should return, so min is not defined for dates. However, min is defined for numbers, and dates can be converted to numbers...but what those numbers actually mean is not necessarily clear. --Adam On Mon, 8 Sep 2008, Erich Studerus wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] How to preserve date format while aggregating
Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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.
Re: [R] How to preserve date format while aggregating
Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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.
Re: [R] How to preserve date format while aggregating
Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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.
Re: [R] How to preserve date format while aggregating
Can you provide some actual data. It sounds like the columns you are are POSIXct, in which case you would want to do something like this: time - structure(time, class = c(POSIXt, POSIXct)) So it is important to know what your numeric values came from and what their actual values were. Which of these values look closer to what you are seeing: as.numeric(as.POSIXct('2008-09-08')) [1] 1220832000 as.numeric(as.Date('2008-09-08')) [1] 14130 On Mon, Sep 8, 2008 at 9:15 AM, Erich Studerus [EMAIL PROTECTED] wrote: Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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.
Re: [R] How to preserve date format while aggregating
Erich, how does the data look, when it comes from SQL? And why not extract the data with SQL directly, so you don't have this issue in the first place? el on 9/8/08 3:15 PM Erich Studerus said the following: Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Dr. Eberhard W. Lisse \/ Obstetrician Gynaecologist (Saar) [EMAIL PROTECTED] el108-ARIN / * | Telephone: +264 81 124 6733 (cell) PO Box 8421 \ / Please do NOT email to this address Bachbrecht, Namibia ;/if it is DNS related in ANY way __ 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.
Re: [R] How to preserve date format while aggregating
Here's how the dates look like after the sql-query: Oav$Date[1:3] [1] 1991-11-22 00:45:00 CET 1991-12-13 00:01:00 CET 1992-02-06 00:45:00 CET class(oav$Date[1:3]) [1] POSIXt POSIXct x-as.numeric(oav$Date[1:3]) x [1] 690767100 692578860 697333500 class(x)-Date x [1] 3226-01-31 8186-07-07 1204-04-11 I wanteded to apply the aggregate function in R instead of in the SQL-query, because R is much more flexible and faster in manipulating large dataframes. Erich -Ursprüngliche Nachricht- Von: Dr Eberhard Lisse [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 15:43 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Erich, how does the data look, when it comes from SQL? And why not extract the data with SQL directly, so you don't have this issue in the first place? el on 9/8/08 3:15 PM Erich Studerus said the following: Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Dr. Eberhard W. Lisse \/ Obstetrician Gynaecologist (Saar) [EMAIL PROTECTED] el108-ARIN / * | Telephone: +264 81 124 6733 (cell) PO Box 8421 \ / Please do NOT email to this address Bachbrecht, Namibia ;/if it is DNS related in ANY way __ 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.
Re: [R] How to preserve date format while aggregating
Those are not dates! They are date-times. aggregate is overkill for a single column. Something simple like DT - seq(Sys.time(), by=4 hours, len=24) grp - rbinom(24, 1, p=0.5) res - tapply(DT, grp, min) class(res) - class(DT) res would suffice. On Mon, 8 Sep 2008, Erich Studerus wrote: Here's how the dates look like after the sql-query: Oav$Date[1:3] [1] 1991-11-22 00:45:00 CET 1991-12-13 00:01:00 CET 1992-02-06 00:45:00 CET class(oav$Date[1:3]) [1] POSIXt POSIXct x-as.numeric(oav$Date[1:3]) x [1] 690767100 692578860 697333500 class(x)-Date x [1] 3226-01-31 8186-07-07 1204-04-11 I wanteded to apply the aggregate function in R instead of in the SQL-query, because R is much more flexible and faster in manipulating large dataframes. Erich -Ursprüngliche Nachricht- Von: Dr Eberhard Lisse [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 15:43 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Erich, how does the data look, when it comes from SQL? And why not extract the data with SQL directly, so you don't have this issue in the first place? el on 9/8/08 3:15 PM Erich Studerus said the following: Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Dr. Eberhard W. Lisse \/ Obstetrician Gynaecologist (Saar) [EMAIL PROTECTED] el108-ARIN / * | Telephone: +264 81 124 6733 (cell) PO Box 8421 \ / Please do NOT email to this address Bachbrecht, Namibia ;/if it is DNS related in ANY way __ 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ 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.
Re: [R] How to preserve date format while aggregating
As requested in the last line to every message to r-help a cutdown version of the data should be posted with the question. Suppose such a cut down version is this: DF - data.frame(Date = ISOdatetime(2008, 1, c(1, 2, 5, 3, 4), 0, 0, 0), Subject = c(1, 1, 2, 2, 2)) # Then sort the data and take first one in each group: DFsort - DF[order(DF$Subject, DF$Date), ] DFsort[!duplicated(DFsort$Subject), ] If its already sorted then omit first line and use DF in place of DFsort in second line. On Mon, Sep 8, 2008 at 9:15 AM, Erich Studerus [EMAIL PROTECTED] wrote: Thanks, I've already tried that. The problem is, that the original date is not restored when I change the numeric back to date. I get a totally different date. Maybe it has something to do with the original date format. My data are directly imported from a SQL-database. The date column to which I want to apply the aggregate function has the two classes POSIXt and POSIXct. Changing the column to class Date before applying the aggregate function did not help. I still get a different date, when I transform it back to class Date. I would be glad, if someone knew a more elegant way to extract the rows with minimum/earliest date per subject. Erich -Ursprüngliche Nachricht- Von: jim holtman [mailto:[EMAIL PROTECTED] Gesendet: Montag, 8. September 2008 14:24 An: Erich Studerus Cc: r-help@r-project.org Betreff: Re: [R] How to preserve date format while aggregating Try changing the 'class' of the numeric result back to Date: x - as.Date('2008-09-08') x [1] 2008-09-08 y - as.numeric(x) y [1] 14130 str(y) num 14130 class(y) - Date y [1] 2008-09-08 str(y) Class 'Date' num 14130 On Mon, Sep 8, 2008 at 6:38 AM, Erich Studerus [EMAIL PROTECTED] wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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.
Re: [R] How to preserve date format while aggregating
Hi Erich, Since min() is defined for numbers and not dates, the problem is in the min() function. min() is converting from date format to number format. Your best bet is to make this conversion explicit...such that it is reversable. So, convert the date into UTC, then UTC to seconds since epoch, then take the minimum, then convert back to UTC time. This sounds like a pain...but that's basically what a version of min() designed to work with dates would do. The reason this is a pain is basically due to timezones: Consider a comparison between x = 3:54 PM September 8 in California (right now where I am) and y = 12:54 AM September 9 in Zurich (right now where you are). Is it earlier here than there? Yes, because it's Sept 8 to your Sept 9. Is it earlier there than here? Yes, because your day started 56 minutes ago, mine over 15 hours ago. Is it the same time here than there? Yes, because our UTC times are equal. So it's not clear what min should return, so min is not defined for dates. However, min is defined for numbers, and dates can be converted to numbers...but what those numbers actually mean is not necessarily clear. --Adam On Mon, 8 Sep 2008, Erich Studerus wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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.
Re: [R] How to preserve date format while aggregating
min does work for POSIXct and Date too: ct - ISOdatetime(2008, 1, 1:10, 0, 0, 0) min(ct) [1] 2008-01-01 EST min(as.Date(ct)) [1] 2008-01-01 On Mon, Sep 8, 2008 at 6:57 PM, Adam D. I. Kramer [EMAIL PROTECTED] wrote: Hi Erich, Since min() is defined for numbers and not dates, the problem is in the min() function. min() is converting from date format to number format. Your best bet is to make this conversion explicit...such that it is reversable. So, convert the date into UTC, then UTC to seconds since epoch, then take the minimum, then convert back to UTC time. This sounds like a pain...but that's basically what a version of min() designed to work with dates would do. The reason this is a pain is basically due to timezones: Consider a comparison between x = 3:54 PM September 8 in California (right now where I am) and y = 12:54 AM September 9 in Zurich (right now where you are). Is it earlier here than there? Yes, because it's Sept 8 to your Sept 9. Is it earlier there than here? Yes, because your day started 56 minutes ago, mine over 15 hours ago. Is it the same time here than there? Yes, because our UTC times are equal. So it's not clear what min should return, so min is not defined for dates. However, min is defined for numbers, and dates can be converted to numbers...but what those numbers actually mean is not necessarily clear. --Adam On Mon, 8 Sep 2008, Erich Studerus wrote: Hi I have a dataframe in which some subjects appear in more than one row. I want to extract the subject-rows which have the minimum date per subject. I tried the following aggregate function. attach(dataframe.xy) aggregate(Date,list(SubjectID),min) Unfortunately, the format of the Date-column changes to numeric, when I'm applying this function. How can I preserve the date format? Thanks Erich __ 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. __ 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.