See if this illustration using the %in% operator within subset() is
helpful:
> df1 <- data.frame(x=1:10, y=sample(c("a","b","c"), 10,
replace=TRUE) )
> uniques <- list("a","b")
>
> Test1 <- subset(df1, y %in% uniques)
> Test1
x y
1 1 b
4 4 a
5 5 b
6 6 b
7 7 a
9 9 a
Next question of cours
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
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 sin
3 matches
Mail list logo