Is there a one-liner that can accomplish this same thing? Essentially I have two dataframes: one that has my raw data (data
), and one that has values that I want to lookup (lookup
). I want to find the percent of values in data
(by 2 factors, Site
and variable
) that are less than the lookup
value for those same 2 factors.
I'd love to just be able add the result to the lookup
dataframe as a column, instead of creating two new objects.
combine <- merge(data, lookup, by = c("Site", "variable"), allow.cartesian = TRUE)
test <- ddply(combine, .(Site, variable), summarize, percent = sum(data.values < lookup.value) / length(data.values))
Any advice is appreciated!