[R] Using Aggregate for Date

Phil Spector spector at stat.berkeley.edu
Tue Feb 8 01:23:43 CET 2011


Belle -
    Assuming that by=list(mydata$schoolid, mydata$year) was a
typo and should have been by=list(mydata$studentid, mydata$year),
setting

class(day_min$x) = 'POSIXct'
day_min$x = format(day_min$x,'%m/%d/%y %l:%M %p')

should make the mininum days display in the format you want.
 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu

On Mon, 7 Feb 2011, Belle wrote:

>
> Hi,
>
> I am trying to find the min of day for each student in each year.
>
> Here is the dataset:
>
> date	                     studentid         year
> 1/1/05 6:07 AM	        236	        20082009
> 3/27/09 9:45 AM	        236	        20082009
> 4/29/09 8:44 AM	        236	        20082009
> 3/27/09 11:36 AM        310	        20082009
> 4/1/09 10:43 AM	        310	        20082009
> 10/15/09 8:54 AM	310	        20092010
> 10/22/09 8:54 AM	310	        20092010
> 10/28/09 8:06 AM	310      	20092010
> 11/19/09 9:06 AM	310    	20092010
> 10/24/07 9:22 AM	335    	20072008
> 12/13/07 9:26 AM	335    	20072008
> 2/25/09 1:49 PM   	335    	20082009
> 3/5/09 2:13 PM    	335    	20082009
> 4/15/09 1:53 PM   	335	       20082009
> 10/24/07 12:14 PM	126    	20072008
> 11/7/07 12:21 PM  	126    	20072008
> 3/19/09 8:45 AM  	177    	20082009
> 4/2/09 8:54 AM     	177     	20082009
> 4/16/09 9:57 AM   	177    	20082009
>
> day_min <- aggregate(mydata$date, by=list(mydata$schoolid, mydata$year),
> FUN=min)
>
> However, the result shows the date is in format as: "1193242974" instead of
> "mm/dd/yy HH:MM AM".
>
> Is there anyway that I can show original date in the result?
> Thanks
>
>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Using-Aggregate-for-Date-tp3265417p3265417.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list