I have a data base with 121 rows and like 10 columns. One of these columns corresponds to Station, another to depth and the rest to chemical variables (temperature, salinity, etc.). I want to calculate the integrated value of these chemical properties by station, using the function oce::integrateTrapezoid. It's my first time doing a loop, so i dont know how. Could you help me?
dA<-matrix(data=NA, nrow=121, ncol=3)
for (Station in unique(datos$Station))
{dA[Station, cd] <- integrateTrapezoid(cd, Profundidad..m., "cA")
}
Station | Depth | temp |
---|---|---|
1 | 10 | 28 |
1 | 50 | 25 |
1 | 100 | 15 |
1 | 150 | 10 |
2 | 9 | 27 |
2 | 45 | 24 |
2 | 98 | 14 |
2 | 152 | 11 |
3 | 11 | 28.7 |
3 | 48 | 23 |
3 | 102 | 14 |
3 | 148 | 9 |