Chapter 8 Exporting Data

Data is easy to export from R. Tables can be exported by piping to readr::write_csv(). For diagrams created in ggplot2, pipe to ggsave(). Sometimes it is necessary to reduce the resolution of Itrax XRF data, usually to facilitate direct comparison with some other lower resolution data. For example, if calibrating using ICP-MS sub-samples taken at 10 mm intervals, but the Itrax XRF scan is at 0.2 mm, it will be necessary to average 50 Itrax measurements for each ICP-MS measurement. This is facilitated using the itrax_reduce() function. The example below demonstrates calculating the averages for contiguous 20 mm chunks of the XRF data.

# get the data as 20 mm intervals
itrax_reduce(CD166_19_xrf %>% drop_na(), by = 20) %>%
  select(-label) %>%
  head()
## # A tibble: 6 × 57
##   resample_names depth   MSE    cps validity    Al    Si     P     S    Cl    Ar
##            <dbl> <dbl> <dbl>  <dbl>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1              1  10.5  1.52 40656.        1  63.9  342      0  25.5 1412.  574.
## 2              2  30.5  1.66 44606.        1  63.4  272.     0  20.8 1307.  627.
## 3              3  50.5  1.66 46712.        1  71    287.     0  14.6 1310.  668.
## 4              4  70.5  1.70 47521.        1  72.7  322.     0  21.9 1490   677.
## 5              5  90.5  1.70 47657.        1  73.8  394.     0  24.8 1515.  691.
## 6              6 110.   1.68 47676.        1  84.4  490.     0  22.2 1507.  652.
## # … with 46 more variables: K <dbl>, Ca <dbl>, Sc <dbl>, Ti <dbl>, V <dbl>,
## #   Cr <dbl>, Mn <dbl>, Fe <dbl>, Ni <dbl>, Cu <dbl>, Zn <dbl>, Ga <dbl>,
## #   Ge <dbl>, Br <dbl>, Rb <dbl>, Sr <dbl>, Y <dbl>, Zr <dbl>, Pd <dbl>,
## #   Cd <dbl>, I <dbl>, Cs <dbl>, Ba <dbl>, Nd <dbl>, Sm <dbl>, Yb <dbl>,
## #   Ta <dbl>, W <dbl>, Pb <dbl>, Bi <dbl>, Mo inc <dbl>, Mo coh <dbl>,
## #   filename <dbl>, position <dbl>, sample surface <dbl>, E-gain <dbl>,
## #   E-offset <dbl>, F-slope <dbl>, F-offset <dbl>, Fe a*2 <dbl>, …