| sortLoadings | R Documentation | 
Sort rows of hyperSpoec object by possition of maximum
value in rows (in other words, sort component spectra, a.k.a. loadings, by
possition of top peak) and do additional tasks:
If sp is provided, convert resulting matrix to corresponding
hyperSpec object by using function
decomposition.
If PCA.flip = TRUE and sp is provided, flip the
loadings of a component in respect with x axis if the mean of the
component's scores is negative:
(sign(mean(Scores_of_component_i)) < 0)
loadings and sp are used to calculate the scores.
sortLoadings(
  loadings,
  sp = NULL,
  PCA.flip = FALSE,
  sort = TRUE,
  label.spc = "Comp. spectra",
  wl.units = "nm"
)
| loadings | Components' spectra (loadings) as either a matrix or a
 | 
| sp | 
 | 
| PCA.flip | Logical. If  
 where  | 
| sort | Logical. Indicates if returned componenst must be sorted.
If  | 
| label.spc | The new label for the matrix of loadings spectra. Default is
 | 
| wl.units | The units of wavelength axis. Will be used as suffix to
values in columns  | 
Either matrix (if sp is not provided) or
hyperSpec object with prepreocessed (sorted, flipped, named, etc.)
loadings.
In case of hyperSpec object, 3 columns
(cNames and PeakAt, order.of.rows) are added/overwritten.
spectra (object of class hyperSpec)
which will be used to convert sorted loadings into
hyperSpec object.
Vilmantas Gegzna
decomposition
Other component analysis / factorisation related functions in spHelper: 
getScores(),
infoDim(),
plot_spDiff(),
qplot_infoDim(),
qplot_kAmp(),
qplot_kSp(),
qplot_spc(),
reconstructSp(),
unipeak(),
whichOutlier()
# Load data
library(spHelper)
data(Loadings2,package = "spHelper")
# ======================================================================
unsorted_loadings <- Loadings2[c(2,3,5,1,4),,]
unsorted_loadings # print unsorted
sortLoadings(unsorted_loadings) # print sorted
# ======================================================================
# Extract loadings as a matrix:
unsorted_loadings_matrix <- Loadings2[c(2,3,5,1,4),,][[]]
# returns a matrix -----
L1 <- sortLoadings(unsorted_loadings_matrix)
class(L1)
## [1] "matrix"
# returns a hyperSpec object -----
L2 <- sortLoadings(unsorted_loadings_matrix, Spectra2)
class(L2)
## [1] "hyperSpec"
# ======================================================================
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.