Calculate number and percentage of unique IDs and observations.

number(IDs) >= number(observations)

# DEFAULT BEHAVIOUR OF FUNCTION CHANGED

nID_nSp(
  data = NULL,
  ID,
  gr,
  ID_text = "medical specimens",
  observation_text = "spectra",
  decimals = 1
)

nID_nObs(
  data = NULL,
  ID,
  gr,
  ID_text = "unique IDs",
  observation_text = "observations"
)

Arguments

data

A data frame with variables, that names are denoted by ID and gr

ID

Vector with speciment IDs (Either a vector or a variable name in data).

gr

Vector with speciment groups (Either a vector or a variable name in data).

ID_text

A title for unique IDs, that apear in the table.

observation_text

A title for observations, that apear in the table.

decimals

A number of maximum decimal places in percentages. This parameter is passed to function round. Default is 0.

Value

Table (data frame) with count and percentages.

Author

Vilmantas Gegzna

Examples

data(DataSet1)

nID_nSp(DataSet1, "ID", "gr")
#>                                 A     B     C     D    
#> Number of medical specimens     "5"   "5"   "5"   "5"  
#> Percentage of medical specimens "25%" "25%" "25%" "25%"
#> Number of spectra               "10"  "10"  "10"  "10" 
#> Percentage of spectra           "25%" "25%" "25%" "25%"
nID_nSp(ID = DataSet1$ID, gr = DataSet1$gr)
#>                                 A     B     C     D    
#> Number of medical specimens     "5"   "5"   "5"   "5"  
#> Percentage of medical specimens "25%" "25%" "25%" "25%"
#> Number of spectra               "10"  "10"  "10"  "10" 
#> Percentage of spectra           "25%" "25%" "25%" "25%"
pander::pander(nID_nSp(DataSet1, "ID", "gr"))
#> 
#> ---------------------------------------------------
#>                          A     B     C     D  
#> --------------------------- ----- ----- ----- -----
#>     **Number of medical       5     5     5     5  
#>         specimens**                                
#> 
#>   **Percentage of medical    25%   25%   25%   25% 
#>         specimens**                                
#> 
#>    **Number of spectra**     10    10    10    10  
#> 
#>  **Percentage of spectra**   25%   25%   25%   25% 
#> ---------------------------------------------------
#> 

nID_nObs(DataSet1, "ID", "gr")
#>                            A     B     C     D    
#> Number of unique IDs       "5"   "5"   "5"   "5"  
#> Percentage of unique IDs   "25%" "25%" "25%" "25%"
#> Number of observations     "10"  "10"  "10"  "10" 
#> Percentage of observations "25%" "25%" "25%" "25%"
pander::pander(nID_nObs(DataSet1, "ID", "gr"))
#> 
#> --------------------------------------------------------
#>                               A     B     C     D  
#> -------------------------------- ----- ----- ----- -----
#>     **Number of unique IDs**       5     5     5     5  
#> 
#>   **Percentage of unique IDs**    25%   25%   25%   25% 
#> 
#>    **Number of observations**     10    10    10    10  
#> 
#>  **Percentage of observations**   25%   25%   25%   25% 
#> --------------------------------------------------------
#> 

# For hyperSpec object
nID_nSp(Spectra2$.., ID = "class", "gr")
#>                                 A       B       C      
#> Number of medical specimens     "4"     "4"     "4"    
#> Percentage of medical specimens "33.3%" "33.3%" "33.3%"
#> Number of spectra               "52"    "55"    "43"   
#> Percentage of spectra           "34.7%" "36.7%" "28.7%"