[R] Problem with the aggregate command

jim holtman jholtman at gmail.com
Sat Sep 8 03:42:59 CEST 2007


Your 'lst' is not the same length as either set1 or set2.  If one of
your columns in the dataframe is the year, then you should have:

aggregate(set1, set1$year, median)

On 9/7/07, Anup Nandialath <anup_nandialath at yahoo.com> wrote:
> Dear friends,
>
> I have a data set with 23 columns and 38000 rows. It is a panel running from the years 1991 through 2005. I want to aggregate the data and get the medians of each of the 23 columns for each of the years. In other words my output should be like this
>
> Year     Median
>
> 1991        123
> 1992        145
> 1993        132
>
> etc.
>
> The sample lines of code to do this operation is
>
> set1 <- subset(as.data.frame(dataset),rep1==1)
> set2 <- subset(as.data.frame(dataset),rep1==0)
> lst <- list(unique(yeara))
>
> y1 <- aggregate(set1,lst,median)
> y2 <- aggregate(set2,lst,median)
>
> However I'm getting an error as follows
> Error in FUN(X[[1]], ...) : arguments must have same length
>
> Can somebody please help me with what I'm doing wrong here?
>
> Thanks in advance
> Regards
>
> Anup
>
>
>
>
> ---------------------------------
>
>        [[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
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list