I have two dataframes (df1
and df2
) and would like to subtract only numeric columns between the two dataframes [(df2-df1)/df2]
and determine the percentage difference and create an output dataframe = df3 using R. Non-numeric columns will be retained as such.
df1
and df2
have the same structure and same column names.
df1:
colA colB colC ... colZ
mean 10 20 stringA
count 30 50 stringB
df2:
colA colB colC ... colZ
mean 5 25 stringA
count 60 50 stringB
df3:
colA colB colC ... colZ
mean -100 20 stringA
count 50 0 stringB
I tried this and didn't work:
df2[,2:3] = (df2[,2:3] - df1[,2:3])/df2[,2:3]
could someone please help with this?