Here i wish to divide the value in each row by the corresponding daily (each row is a day) maximum value, how would i do this? Finding it tricky as i dont want to divide the first 2 columns of the data by this. Data snipet below;
so i want to divide each of the values in each row by the max in each row but avoiding the date and substation
Date Substation `00:00` `00:10` `00:20` `00:30` `00:40` `00:50` `01:00` `01:10` `01:20` max
<date> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 2013-01-03 511016 257. 259. 264. 263. 248. 239. 243. 230. 228. 264.
2 2013-01-03 511029 96 111. 116. 99.0 123. 128. 130. 126. 116. 130.
3 2013-01-03 511030 138. 129. 127. 124. 119. 126. 125. 121. 112. 138.
4 2013-01-03 511033 172. 165. 167. 170. 171. 173. 173. 166. 157. 173.
5 2013-01-03 511034 302. 298. 302. 290. 291. 287. 280. 291. 277. 302.
6 2013-01-03 511035 116. 131. 130. 121. 116. 108. 106. 112. 109. 131.
>Solution :
With pmax and do.call:
df[-c(1, 2)] / do.call(pmax, df[-c(1, 2)])
Or, you can apply a function, x / max(x), for each rows (MARGIN = 1) of your selected columns (df[-c(1, 2)]) using apply.
t(apply(df[-c(1, 2)], 1, function(x) x / max(x)))