Skip to contents

adj_res() and conform_res() are helper functions to align wavenumbers in terms of their spectral resolution. adj_neg() converts numeric intensities y < 1 into values >= 1, keeping absolute differences between intensity values by shifting each value by the minimum intensity. make_rel() converts intensities y into relative values between 0 and 1 using the standard normalization equation. If na.rm is TRUE, missing values are removed before the computation proceeds.

Usage

adj_res(x, res = 1, fun = round)

conform_res(x, res = 5)

adj_neg(y, na.rm = FALSE)

mean_replace(y, na.rm = TRUE)

is_empty_vector(x)

Arguments

x

a numeric vector or an R object which is coercible to one by as.vector(x, "numeric"); x should contain the spectral wavenumbers.

res

spectral resolution supplied to fun.

fun

the function to be applied to each element of x; defaults to round() to round to a specific resolution res.

y

a numeric vector containing the spectral intensities.

na.rm

logical. Should missing values be removed?

Value

adj_res() and conform_res() return a numeric vector with resolution-conformed wavenumbers. adj_neg() and make_rel() return numeric vectors with the normalized intensity data.

Details

adj_res() and conform_res() are used in Open Specy to facilitate comparisons of spectra with different resolutions. adj_neg() is used to avoid errors that could arise from log transforming spectra when using adj_intens() and other functions. make_rel() is used to retain the relative height proportions between spectra while avoiding the large numbers that can result from some spectral instruments.

See also

min() and round(); adj_intens() for log transformation functions; conform_spec() for conforming wavenumbers of an OpenSpecy object to be matched with a reference library

Author

Win Cowger, Zacharias Steinmetz

Examples

adj_res(seq(500, 4000, 4), 5)
#>   [1]  500  505  510  510  515  520  525  530  530  535  540  545  550  550  555
#>  [16]  560  565  570  570  575  580  585  590  590  595  600  605  610  610  615
#>  [31]  620  625  630  630  635  640  645  650  650  655  660  665  670  670  675
#>  [46]  680  685  690  690  695  700  705  710  710  715  720  725  730  730  735
#>  [61]  740  745  750  750  755  760  765  770  770  775  780  785  790  790  795
#>  [76]  800  805  810  810  815  820  825  830  830  835  840  845  850  850  855
#>  [91]  860  865  870  870  875  880  885  890  890  895  900  905  910  910  915
#> [106]  920  925  930  930  935  940  945  950  950  955  960  965  970  970  975
#> [121]  980  985  990  990  995 1000 1005 1010 1010 1015 1020 1025 1030 1030 1035
#> [136] 1040 1045 1050 1050 1055 1060 1065 1070 1070 1075 1080 1085 1090 1090 1095
#> [151] 1100 1105 1110 1110 1115 1120 1125 1130 1130 1135 1140 1145 1150 1150 1155
#> [166] 1160 1165 1170 1170 1175 1180 1185 1190 1190 1195 1200 1205 1210 1210 1215
#> [181] 1220 1225 1230 1230 1235 1240 1245 1250 1250 1255 1260 1265 1270 1270 1275
#> [196] 1280 1285 1290 1290 1295 1300 1305 1310 1310 1315 1320 1325 1330 1330 1335
#> [211] 1340 1345 1350 1350 1355 1360 1365 1370 1370 1375 1380 1385 1390 1390 1395
#> [226] 1400 1405 1410 1410 1415 1420 1425 1430 1430 1435 1440 1445 1450 1450 1455
#> [241] 1460 1465 1470 1470 1475 1480 1485 1490 1490 1495 1500 1505 1510 1510 1515
#> [256] 1520 1525 1530 1530 1535 1540 1545 1550 1550 1555 1560 1565 1570 1570 1575
#> [271] 1580 1585 1590 1590 1595 1600 1605 1610 1610 1615 1620 1625 1630 1630 1635
#> [286] 1640 1645 1650 1650 1655 1660 1665 1670 1670 1675 1680 1685 1690 1690 1695
#> [301] 1700 1705 1710 1710 1715 1720 1725 1730 1730 1735 1740 1745 1750 1750 1755
#> [316] 1760 1765 1770 1770 1775 1780 1785 1790 1790 1795 1800 1805 1810 1810 1815
#> [331] 1820 1825 1830 1830 1835 1840 1845 1850 1850 1855 1860 1865 1870 1870 1875
#> [346] 1880 1885 1890 1890 1895 1900 1905 1910 1910 1915 1920 1925 1930 1930 1935
#> [361] 1940 1945 1950 1950 1955 1960 1965 1970 1970 1975 1980 1985 1990 1990 1995
#> [376] 2000 2005 2010 2010 2015 2020 2025 2030 2030 2035 2040 2045 2050 2050 2055
#> [391] 2060 2065 2070 2070 2075 2080 2085 2090 2090 2095 2100 2105 2110 2110 2115
#> [406] 2120 2125 2130 2130 2135 2140 2145 2150 2150 2155 2160 2165 2170 2170 2175
#> [421] 2180 2185 2190 2190 2195 2200 2205 2210 2210 2215 2220 2225 2230 2230 2235
#> [436] 2240 2245 2250 2250 2255 2260 2265 2270 2270 2275 2280 2285 2290 2290 2295
#> [451] 2300 2305 2310 2310 2315 2320 2325 2330 2330 2335 2340 2345 2350 2350 2355
#> [466] 2360 2365 2370 2370 2375 2380 2385 2390 2390 2395 2400 2405 2410 2410 2415
#> [481] 2420 2425 2430 2430 2435 2440 2445 2450 2450 2455 2460 2465 2470 2470 2475
#> [496] 2480 2485 2490 2490 2495 2500 2505 2510 2510 2515 2520 2525 2530 2530 2535
#> [511] 2540 2545 2550 2550 2555 2560 2565 2570 2570 2575 2580 2585 2590 2590 2595
#> [526] 2600 2605 2610 2610 2615 2620 2625 2630 2630 2635 2640 2645 2650 2650 2655
#> [541] 2660 2665 2670 2670 2675 2680 2685 2690 2690 2695 2700 2705 2710 2710 2715
#> [556] 2720 2725 2730 2730 2735 2740 2745 2750 2750 2755 2760 2765 2770 2770 2775
#> [571] 2780 2785 2790 2790 2795 2800 2805 2810 2810 2815 2820 2825 2830 2830 2835
#> [586] 2840 2845 2850 2850 2855 2860 2865 2870 2870 2875 2880 2885 2890 2890 2895
#> [601] 2900 2905 2910 2910 2915 2920 2925 2930 2930 2935 2940 2945 2950 2950 2955
#> [616] 2960 2965 2970 2970 2975 2980 2985 2990 2990 2995 3000 3005 3010 3010 3015
#> [631] 3020 3025 3030 3030 3035 3040 3045 3050 3050 3055 3060 3065 3070 3070 3075
#> [646] 3080 3085 3090 3090 3095 3100 3105 3110 3110 3115 3120 3125 3130 3130 3135
#> [661] 3140 3145 3150 3150 3155 3160 3165 3170 3170 3175 3180 3185 3190 3190 3195
#> [676] 3200 3205 3210 3210 3215 3220 3225 3230 3230 3235 3240 3245 3250 3250 3255
#> [691] 3260 3265 3270 3270 3275 3280 3285 3290 3290 3295 3300 3305 3310 3310 3315
#> [706] 3320 3325 3330 3330 3335 3340 3345 3350 3350 3355 3360 3365 3370 3370 3375
#> [721] 3380 3385 3390 3390 3395 3400 3405 3410 3410 3415 3420 3425 3430 3430 3435
#> [736] 3440 3445 3450 3450 3455 3460 3465 3470 3470 3475 3480 3485 3490 3490 3495
#> [751] 3500 3505 3510 3510 3515 3520 3525 3530 3530 3535 3540 3545 3550 3550 3555
#> [766] 3560 3565 3570 3570 3575 3580 3585 3590 3590 3595 3600 3605 3610 3610 3615
#> [781] 3620 3625 3630 3630 3635 3640 3645 3650 3650 3655 3660 3665 3670 3670 3675
#> [796] 3680 3685 3690 3690 3695 3700 3705 3710 3710 3715 3720 3725 3730 3730 3735
#> [811] 3740 3745 3750 3750 3755 3760 3765 3770 3770 3775 3780 3785 3790 3790 3795
#> [826] 3800 3805 3810 3810 3815 3820 3825 3830 3830 3835 3840 3845 3850 3850 3855
#> [841] 3860 3865 3870 3870 3875 3880 3885 3890 3890 3895 3900 3905 3910 3910 3915
#> [856] 3920 3925 3930 3930 3935 3940 3945 3950 3950 3955 3960 3965 3970 3970 3975
#> [871] 3980 3985 3990 3990 3995 4000
conform_res(seq(500, 4000, 4))
#>   [1]  500  505  510  515  520  525  530  535  540  545  550  555  560  565  570
#>  [16]  575  580  585  590  595  600  605  610  615  620  625  630  635  640  645
#>  [31]  650  655  660  665  670  675  680  685  690  695  700  705  710  715  720
#>  [46]  725  730  735  740  745  750  755  760  765  770  775  780  785  790  795
#>  [61]  800  805  810  815  820  825  830  835  840  845  850  855  860  865  870
#>  [76]  875  880  885  890  895  900  905  910  915  920  925  930  935  940  945
#>  [91]  950  955  960  965  970  975  980  985  990  995 1000 1005 1010 1015 1020
#> [106] 1025 1030 1035 1040 1045 1050 1055 1060 1065 1070 1075 1080 1085 1090 1095
#> [121] 1100 1105 1110 1115 1120 1125 1130 1135 1140 1145 1150 1155 1160 1165 1170
#> [136] 1175 1180 1185 1190 1195 1200 1205 1210 1215 1220 1225 1230 1235 1240 1245
#> [151] 1250 1255 1260 1265 1270 1275 1280 1285 1290 1295 1300 1305 1310 1315 1320
#> [166] 1325 1330 1335 1340 1345 1350 1355 1360 1365 1370 1375 1380 1385 1390 1395
#> [181] 1400 1405 1410 1415 1420 1425 1430 1435 1440 1445 1450 1455 1460 1465 1470
#> [196] 1475 1480 1485 1490 1495 1500 1505 1510 1515 1520 1525 1530 1535 1540 1545
#> [211] 1550 1555 1560 1565 1570 1575 1580 1585 1590 1595 1600 1605 1610 1615 1620
#> [226] 1625 1630 1635 1640 1645 1650 1655 1660 1665 1670 1675 1680 1685 1690 1695
#> [241] 1700 1705 1710 1715 1720 1725 1730 1735 1740 1745 1750 1755 1760 1765 1770
#> [256] 1775 1780 1785 1790 1795 1800 1805 1810 1815 1820 1825 1830 1835 1840 1845
#> [271] 1850 1855 1860 1865 1870 1875 1880 1885 1890 1895 1900 1905 1910 1915 1920
#> [286] 1925 1930 1935 1940 1945 1950 1955 1960 1965 1970 1975 1980 1985 1990 1995
#> [301] 2000 2005 2010 2015 2020 2025 2030 2035 2040 2045 2050 2055 2060 2065 2070
#> [316] 2075 2080 2085 2090 2095 2100 2105 2110 2115 2120 2125 2130 2135 2140 2145
#> [331] 2150 2155 2160 2165 2170 2175 2180 2185 2190 2195 2200 2205 2210 2215 2220
#> [346] 2225 2230 2235 2240 2245 2250 2255 2260 2265 2270 2275 2280 2285 2290 2295
#> [361] 2300 2305 2310 2315 2320 2325 2330 2335 2340 2345 2350 2355 2360 2365 2370
#> [376] 2375 2380 2385 2390 2395 2400 2405 2410 2415 2420 2425 2430 2435 2440 2445
#> [391] 2450 2455 2460 2465 2470 2475 2480 2485 2490 2495 2500 2505 2510 2515 2520
#> [406] 2525 2530 2535 2540 2545 2550 2555 2560 2565 2570 2575 2580 2585 2590 2595
#> [421] 2600 2605 2610 2615 2620 2625 2630 2635 2640 2645 2650 2655 2660 2665 2670
#> [436] 2675 2680 2685 2690 2695 2700 2705 2710 2715 2720 2725 2730 2735 2740 2745
#> [451] 2750 2755 2760 2765 2770 2775 2780 2785 2790 2795 2800 2805 2810 2815 2820
#> [466] 2825 2830 2835 2840 2845 2850 2855 2860 2865 2870 2875 2880 2885 2890 2895
#> [481] 2900 2905 2910 2915 2920 2925 2930 2935 2940 2945 2950 2955 2960 2965 2970
#> [496] 2975 2980 2985 2990 2995 3000 3005 3010 3015 3020 3025 3030 3035 3040 3045
#> [511] 3050 3055 3060 3065 3070 3075 3080 3085 3090 3095 3100 3105 3110 3115 3120
#> [526] 3125 3130 3135 3140 3145 3150 3155 3160 3165 3170 3175 3180 3185 3190 3195
#> [541] 3200 3205 3210 3215 3220 3225 3230 3235 3240 3245 3250 3255 3260 3265 3270
#> [556] 3275 3280 3285 3290 3295 3300 3305 3310 3315 3320 3325 3330 3335 3340 3345
#> [571] 3350 3355 3360 3365 3370 3375 3380 3385 3390 3395 3400 3405 3410 3415 3420
#> [586] 3425 3430 3435 3440 3445 3450 3455 3460 3465 3470 3475 3480 3485 3490 3495
#> [601] 3500 3505 3510 3515 3520 3525 3530 3535 3540 3545 3550 3555 3560 3565 3570
#> [616] 3575 3580 3585 3590 3595 3600 3605 3610 3615 3620 3625 3630 3635 3640 3645
#> [631] 3650 3655 3660 3665 3670 3675 3680 3685 3690 3695 3700 3705 3710 3715 3720
#> [646] 3725 3730 3735 3740 3745 3750 3755 3760 3765 3770 3775 3780 3785 3790 3795
#> [661] 3800 3805 3810 3815 3820 3825 3830 3835 3840 3845 3850 3855 3860 3865 3870
#> [676] 3875 3880 3885 3890 3895 3900 3905 3910 3915 3920 3925 3930 3935 3940 3945
#> [691] 3950 3955 3960 3965 3970 3975 3980 3985 3990 3995 4000
adj_neg(c(-1000, -1, 0, 1, 10))
#> [1]    1 1000 1001 1002 1011
make_rel(c(-1000, -1, 0, 1, 10))
#> [1] 0.0000000 0.9891089 0.9900990 0.9910891 1.0000000