Function to remove the table rows for which all measurements of interest are non-available (NA). A particular list of measurement names can be explicitly provided or selected by a common initial pattern. The default setting removes the rows with no log-ratio available.

RemoveNACases(data, measureNames = NULL, prefix = logPrefix)

Arguments

data

A dataframe with the input measurements.

measureNames

A vector of characters with the list of measurements to be considered for missing values. If NULL (default), all measurements starting by prefix are considered.

prefix

A character string with the initial pattern to select the list of measurements. The default is given by the internal variable logPrefix. It is in effect only when measureNames = NULL.

Value

A dataframe with the same columns as the input dataframe but removing the rows with missing values for all measurements in the list.

Examples

## Read an example dataset:
dataFile <- system.file("extdata", "dataValenzuelaLamas2008.csv.gz",
                        package = "zoolog")
dataExample <- utils::read.csv2(dataFile,
                                na.strings = "",
                                encoding = "UTF-8")
## We can observe the first lines (excluding some columns for visibility):
head(dataExample)[, -c(6:20,32:64)]
#>   Site N.inv    UE Especie       Os   GL    Bp   Dp   SD   DD   Bd   Dd   BT
#> 1  ALP  4918 10364    bota    1 fal 54.0  31.3 30.6 28.1 26.3 27.5 20.0   NA
#> 2  ALP  4919 10364    bota    1 fal 54.5  27.9 31.8 26.0 22.8 25.3 19.5   NA
#> 3  ALP  3453 10410    ovar 1fal ant 27.1   9.9 12.3 17.9  9.0  9.0   NA   NA
#> 4  ALP  3455 10410    ovar 1fal ant 27.6   9.6 12.2  7.6  8.9  8.3   NA   NA
#> 5  ALP  4245  7036    cahi      hum   NA 128.3   NA 12.9   NA 27.4 26.6 23.6
#> 6  ALP  4674 10227    cahi      hum   NA    NA   NA   NA   NA 26.0 25.7 22.3
#>   GLc BFd Dl
#> 1  NA  NA NA
#> 2  NA  NA NA
#> 3  NA  NA NA
#> 4  NA  NA NA
#> 5  NA  NA NA
#> 6  NA  NA NA

## Remove the cases not including any measurement present in the reference.
refMeasureNames <- unique(reference$Combi$Measure)
refMeasureNames
#>  [1] GL                                   GLc                                 
#>  [3] Bp                                   Dp                                  
#>  [5] SD                                   Bd                                  
#>  [7] BT                                   HTC                                 
#>  [9] Dd                                   BFp                                 
#> [11] BFd                                  GLl                                 
#> [13] GLpe                                 SLC                                 
#> [15] GLP                                  LG                                  
#> [17] BG                                   DPA                                 
#> [19] BPC                                  WCM                                 
#> [21] LA                                   DC                                  
#> [23] Dl                                   GB                                  
#> [25] L                                    H                                   
#> [27] SDO                                  LAR                                 
#> [29] SH                                   GLm                                 
#> [31] LeP                                  GL                                  
#> [33] DEM                                  DVM                                 
#> [35] DEL                                  DVL                                 
#> [37] WCL                                  Dm                                  
#> [39] 1                                    2                                   
#> [41] 3                                    9                                   
#> [43] 10                                   24                                  
#> [45] 34                                   38                                  
#> [47] 40                                   41                                  
#> [49] 43                                   45                                  
#> [51] 48                                   50                                  
#> [53] GLC                                  Ll                                  
#> [55] DFd                                  GH                                  
#> [57] DS                                   GLT                                 
#> [59] SBT                                  SDT                                 
#> [61] GBT                                  GDT                                 
#> [63] HS                                   LFo                                 
#> [65] SB                                   GLF                                 
#> [67] BFcr                                 BFcd                                
#> [69] Breadth of caudal channel            LCDe                                
#> [71] Breadth of cranial channel           LAPa                                
#> [73] SBV                                  BPtr                                
#> [75] BPacd                                PL                                  
#> [77] HFcr                                 DHA                                 
#> [79] Breadth of acetabulum                LS                                  
#> [81] Depth                                Distal depth, flat against posterior
#> [83] Maximum lateral depth               
#> 83 Levels: BFd BFp BT Bd Bp Dd Dp GL GLc GLl GLpe HTC SD BG BPC DC DPA ... SBV
dataExamplePruned <- RemoveNACases(dataExample,
                                   measureNames = refMeasureNames)
## The first lines of the output data frame show at least one available
## measurement value in the selected list:
head(dataExamplePruned)[, -c(6:20,32:64)]
#>   Site N.inv    UE Especie       Os   GL    Bp   Dp   SD   DD   Bd   Dd   BT
#> 1  ALP  4918 10364    bota    1 fal 54.0  31.3 30.6 28.1 26.3 27.5 20.0   NA
#> 2  ALP  4919 10364    bota    1 fal 54.5  27.9 31.8 26.0 22.8 25.3 19.5   NA
#> 3  ALP  3453 10410    ovar 1fal ant 27.1   9.9 12.3 17.9  9.0  9.0   NA   NA
#> 4  ALP  3455 10410    ovar 1fal ant 27.6   9.6 12.2  7.6  8.9  8.3   NA   NA
#> 5  ALP  4245  7036    cahi      hum   NA 128.3   NA 12.9   NA 27.4 26.6 23.6
#> 6  ALP  4674 10227    cahi      hum   NA    NA   NA   NA   NA 26.0 25.7 22.3
#>   GLc BFd Dl
#> 1  NA  NA NA
#> 2  NA  NA NA
#> 3  NA  NA NA
#> 4  NA  NA NA
#> 5  NA  NA NA
#> 6  NA  NA NA

## If we compute first the log-ratios
dataExampleWithLogs <- LogRatios(dataExample)
#> Warning: Reference for Sus scrofa used for cases of Sus domesticus.
#>    Reference for Sus scrofa used for cases of Sus.
#>    Reference for Oryctolagus cuniculus used for cases of Oryctolagus.
#>    Reference for Canis lupus used for cases of Canis.
#>    Reference for Ovis aries used for cases of Ovis.
#>    Set useGenusIfUnambiguous to FALSE if this behaviour is not desired.
#> Warning: Data includes some cases recorded as
#>     * Equus (which is a Genus)
#>       for which the reference for Equus asinus or Equus caballus could be used.
#>     * Caprini (which is a Tribe)
#>       for which the reference for Ovis aries or Capra hircus could be used.
#>    Set joinCategories as appropriate if you want to use any of them.
## the cases not including any log-ratio can be removed with the
## default logPrefix
dataExampleWithLogsPruned <- RemoveNACases(dataExampleWithLogs)
head(dataExampleWithLogsPruned)[, -c(6:20,32:64)]
#>   Site N.inv    UE Especie       Os    GL    Bp   Dp   SD   DD   Bd   Dd   BT
#> 1  ALP  3453 10410    ovar 1fal ant  27.1   9.9 12.3 17.9  9.0  9.0   NA   NA
#> 2  ALP  3455 10410    ovar 1fal ant  27.6   9.6 12.2  7.6  8.9  8.3   NA   NA
#> 3  ALP  4245  7036    cahi      hum    NA 128.3   NA 12.9   NA 27.4 26.6 23.6
#> 4  ALP  4674 10227    cahi      hum    NA    NA   NA   NA   NA 26.0 25.7 22.3
#> 5  ALP  4085 10253    cahi      hum    NA    NA   NA   NA   NA 27.9 27.3 23.2
#> 6  TFC    24   407    ceel       mc 262.7  41.3 30.8 25.0 21.2 41.1 27.1   NA
#>   GLc BFd Dl logGL       logBp       logDp      logSD       logBd       logDd
#> 1  NA  NA NA    NA -0.07991177 -0.07265930  0.2629585 -0.08911977          NA
#> 2  NA  NA NA    NA -0.09327573 -0.07620458 -0.1090810 -0.12428419          NA
#> 3  NA  NA NA    NA  0.40167955          NA -0.2116296 -0.15130497 -0.06787875
#> 4  NA  NA NA    NA          NA          NA         NA -0.17408218 -0.08282727
#> 5  NA  NA NA    NA          NA          NA         NA -0.14345133 -0.05659774
#> 6  NA  NA NA    NA          NA          NA         NA -0.03354115          NA
#>   logBT logGLc logBFd logDl logGB logSLC logGLP logBG logLG logDPA logBPC logLA
#> 1    NA     NA     NA    NA    NA     NA     NA    NA    NA     NA     NA    NA
#> 2    NA     NA     NA    NA    NA     NA     NA    NA    NA     NA     NA    NA
#> 3    NA     NA     NA    NA    NA     NA     NA    NA    NA     NA     NA    NA
#> 4    NA     NA     NA    NA    NA     NA     NA    NA    NA     NA     NA    NA
#> 5    NA     NA     NA    NA    NA     NA     NA    NA    NA     NA     NA    NA
#> 6    NA     NA     NA    NA    NA     NA     NA    NA    NA     NA     NA    NA
#>   logLAR logSH logSB logL logH
#> 1     NA    NA    NA   NA   NA
#> 2     NA    NA    NA   NA   NA
#> 3     NA    NA    NA   NA   NA
#> 4     NA    NA    NA   NA   NA
#> 5     NA    NA    NA   NA   NA
#> 6     NA    NA    NA   NA   NA