I need help to create a corrected dataframe X by subtracting first 2 columns of dataframe Y from first 2 columns of raw dataframe X. subtract first 2 columns of dataframe Z from last 2 columns in raw dataframe X
corrected dataframe X (colA - colE), (colB-colF), (colC-colI), (colD-colJ) for same timestamp values.
e.g.
raw data frame X
Timestamp A B C D
00:00 12 10 30 20
00:05 15 12 11 10
00:10 14 11 13 19
00:15 15 15 13 15
00:20 10 13 11 17
data frame Y
Timestamp E F G H
00:00 9 0 8 0
00:05 1 2 1 1
00:10 8 1 4 9
00:15 12 5 6 5
00:20 1 3 9 7
data frame Z
Timestamp I J K F
00:00 9 0 8 0
00:05 1 2 1 1
00:10 8 1 4 9
00:15 12 5 6 5
00:20 1 3 9 7
Corrected Dataframe X
Timestamp A B C D
00:00 3 10 21 20
00:05 14 10 10 8
00:10 6 10 5 18
00:15 3 10 1 10
00:20 9 10 10 14
Assuming that 'Timestamp' is the 1st column, we substract the 2nd and 3rd columns of 'X' with that of 'Y' and update the 2nd and 3rd column by assigning the output. Similarly, we subtract the 4th and 5th column of 'X' with the 2nd and 3rd column of 'Z'.
X[,2:3] <- X[,2:3]-Y[,2:3]
X[,4:5] <- X[,4:5]-Z[,2:3]
X
# Timestamp A B C D
#1 00:00 3 10 21 20
#2 00:05 14 10 10 8
#3 00:10 6 10 5 18
#4 00:15 3 10 1 10
#5 00:20 9 10 10 14