Reputation: 609
I've got this setup and running in an Access DB, but I'm having difficulty translating this into R.
Dataframe A:
ID, B1, B2, B3, group
1, 0.2, 0.4, 1000, red
...
4447, 0.4, 0.32, 800, blue
Dataframe B (mean of columns from Dataframe A, based on column "group":
ID, group, meanB1, meanB2, meanB3
1, red, 0.45, 0.313, 990.32
...
6, blue, 0.39, 0.289, 790.54
There's also a third Dataframe C, which is the standard deviation of columns in Dataframe A, again, based on column "group".
I have an equation (simplified here) that I want to calculate for each line of Dataframe A, but it requires an input from associated entry in Dataframe B, like so:
FuncZ <- function(a, b, c) {(((a - b)/c)^2)}
Where a
is line from Dataframe A (e.g., 4477), and b
from Dataframe B (e.g., red), and c
from Dataframe C (e.g., red).
This is relatively easy in Access, but I'd like to do it the R way.
Upvotes: 0
Views: 197
Reputation: 17412
1) Merge by group
BigDataFrame <- merge(DataFrameA, DataFrameB, DataFrameC, by="group")
2) Evaluate within scope of new data.frame
with(BigDataFrame, (((a - b)/c)^2))
Upvotes: 1