[R] subsets problem

Sundar Dorai-Raj sdorairaj at gmail.com
Mon Feb 9 02:11:01 CET 2009


you can try

lapply(lapply(uniques, function(x) subset(df, date == x)), myfun)

or possibly more accurate (subset may be finicky due to scoping):

lapply(lapply(uniques, function(x) df[df$date == x, ]), myfun)

or use ?split

lapply(split(df, df$date), myfun)

HTH,

--sundar

On Sun, Feb 8, 2009 at 5:00 PM, glenn <g1enn.roberts at btinternet.com> wrote:
> Help with this much appreciated
>
>
>
> I have a large dataframe that I would like to subset where the constraint
>
>
>
> Test1 <- subset(df, date == uniques[[1]]), where uniques is a list of dates
> that must be matched to create Test1.
>
>
>
> I would like to perform an operation on Test1 that results in a single
> column of data. So far so good.
>
>
>
> How do loop through all values in the uniques list (say there is 50),
> perform an operationon Test1,,,,Test50, and then bolt all the lists together
> in a single list please ?
>
>
>
> Regards
>
>
>
>
>
> Glenn
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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