i am having some troubles to find the best and most efficient way to perform few calculations on my data in shiny app. I would like to at first calculate the difference between all the columns (except ID
) to one column, create new columns for each (with specific name) and furthermore perform small calculation. I am going to explain it on the example data:
data <- structure(list(ID = 1:2, Zeit600 = c(601.782608695652, 602.625
), Zeit650 = c(504.705882352941, 546.666666666667), Zeit700 = c(321.26582278481,
316.666666666667), Zeit750 = c(264.303797468354, 261.111111111111
), Zeit800 = c(207.341772151899, 205.555555555556)), row.names = c(NA,
-2L), .Names = c("ID", "Zeit600", "Zeit650", "Zeit700", "Zeit750",
"Zeit800"), class = "data.frame")
Here is the same data in a form that its easier to have a look at:
ID Zeit600 Zeit650 Zeit700 Zeit750 Zeit800
1 1 601.7826 504.7059 321.2658 264.3038 207.3418
2 2 602.6250 546.6667 316.6667 261.1111 205.5556
What i would like to do is to:
1. Calculate the difference between all the columns (except ID
) to column named Zeit800
and named it (if it is possible T800_the number next to Zeit).
*My original data is reactive in shiny, therefore the number of columns Zeit...
will differ, only column Zeit800
always stays.
The result will look like this:
ID Zeit600 Zeit650 Zeit700 Zeit750 Zeit800 T800_T600 T800_T650 T800_T700 T800_T750
1 1 601.7826 504.7059 321.2658 264.3038 207.3418 394.4408 297.3641 113.9241 56.96203
2 2 602.6250 546.6667 316.6667 261.1111 205.5556 397.0694 341.1111 111.1111 55.55556
2. Then i would like to perform small calculation, Calculate the difference between 800 and number which is next Zeit...
in column names, and divide it by calculated values performed above at point 1 (T800...
). So for example lets calculate this for column Zeit600
for ID=1
:
800-600/T800_600 = 800-600/394.4408 = 0.507
The whole data frame would look like:
ID Zeit600 Zeit650 Zeit700 Zeit750 Zeit800 T800_T600 T800_T650 T800_T700 T800_T750 Abkuehlrate_T800_600 Abkuehlrate_T800_650
1 1 601.7826 504.7059 321.2658 264.3038 207.3418 394.4408 297.3641 113.9241 56.96203 0.5070469 0.5044321
2 2 602.6250 546.6667 316.6667 261.1111 205.5556 397.0694 341.1111 111.1111 55.55556 0.5036902 0.4397394
Abkuehlrate_T800_700 Abkuehlrate_T800_750
1 0.8777778 0.8777778
2 0.9000000 0.9000000
Thanks for help!