Hi everyone, I'm freshly using R and I'm having some problem with my code.
I have a huge data frame (df1) of some economic data like this:
state account t1 t2 t3 t4 sum
<list> <list> <int> <list> <int> <list> <int> <list> <int> <list> <int> <list>
st1 account1 1 2 3 1 7
st1 account2 2 3 1 2 8
st1 account3 1 2 1 3 7
st1 account4 1 1 1 1 4
st2 account1 0 4 6 1 11
st2 account2 1 1 2 2 6
st2 account3 2 3 1 2 8
st2 account4 3 5 1 2 11
. . . . . . .
. . . . . . .
. . . . . . .
And another dataframe (df2) with some results of (df1) as:
state account value
<list> <list> <int> <list>
st1 result_t1 1
st1 result_t2 2
st1 result_t3 1
st1 result_t4 1
st2 result_t1 0
st2 result_t2 1
st2 result_t3 2
st2 result_t4 3
. . .
. . .
. . .
I need to create a new df (df3) to do some operations between the accounts over time (t1 to t4), like:
result_t1 = account1_t1 - account2_t1 - account3_t1 + account4_t1
result_t2 = account1_t2 - account2_t2 - account3_t2 + account4_t2
result_t3 = account1_t3 - account2_t3 - account3_t3 + account4_t3
result_t4 = account1_t4 - account2_t4 - account3_t4 + account4_t4
I tried something like this, but did not worked:
result~ x1 - x2 - x3 + x4
x1 <- df1$Account("Account1")
x2 <- df1$Account("Account2")
x3 <- df1$Account("Account3")
x4 <- df1$Account("Account4")
After the operation I need to check if the result in the new lines of (df3) are equal to the result in (df2), and this I really don't know begin to solve this.
The desirable output would be something like the data of the operations of (df3), the values of (df2) and one column to say if they're equal or not, like:
(from (from (from (from
df2) df2) df2) df3)
state account value value equal?
<list> <list> <int> <list> <int> <list> <list>
st1 result_t1 1 1 yes
st1 result_t2 2 2 yes
st1 result_t3 1 0 no
st1 result_t4 1 1 yes
st2 result_t1 0 0 yes
st2 result_t2 1 1 yes
st2 result_t3 2 2 yes
st2 result_t4 3 3 yes
. . . . .
. . . . .
. . . . .
So, anyone knows how to help me to solve this?