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", stringsAsFactors = TRUE) ## 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 <- levels(factor(reference$Combi$Measure)) refMeasureNames
#> [1] "BFd" "BFp" "BT" "Bd" "Bp" "Dd" "Dp" "GL" "GLc" "GLl" #> [11] "HTC" "SD" "BG" "BPC" "DC" "DPA" "Dl" "GB" "GLP" "H" #> [21] "L" "LA" "LG" "SLC" "WCM" "GLm" "LAR" "LeP" "SDO" "SH" #> [31] "DEL" "DEM " "DVL" "DVM" "Dm" "GL " "GLpe" "WCL" "1" "10" #> [41] "2" "24" "3" "34" "38" "40" "41" "43" "45" "48" #> [51] "50" "9" "DFd" "DS" "GH" "GLC" "Ll" "GBT" "GDT" "GLT" #> [61] "HS" "LFo" "SB" "SBT" "SDT"
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) ## 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 #> 1 NA NA NA -0.10786052 -0.07991177 -0.07265930 0.2629585 -0.08911977 #> 2 NA NA NA -0.09992073 -0.09327573 -0.07620458 -0.1090810 -0.12428419 #> 3 NA NA NA NA 0.40167955 NA -0.2116296 -0.15130497 #> 4 NA NA NA NA NA NA NA -0.17408218 #> 5 NA NA NA NA NA NA NA -0.14345133 #> 6 NA NA NA NA NA NA NA -0.03354115 #> logDd logBT logGLc logBFd logDl logGB logSLC logGLP logBG logLG logDPA #> 1 NA NA NA NA NA NA NA NA NA NA NA #> 2 NA NA NA NA NA NA NA NA NA NA NA #> 3 -0.06787875 NA NA NA NA NA NA NA NA NA NA #> 4 -0.08282727 NA NA NA NA NA NA NA NA NA NA #> 5 -0.05659774 NA NA NA NA NA NA NA NA NA NA #> 6 NA NA NA NA NA NA NA NA NA NA NA #> logBPC logLA logLAR logSH logSB logL logH #> 1 NA NA NA NA NA NA NA #> 2 NA NA NA NA NA NA NA #> 3 NA NA NA NA NA NA NA #> 4 NA NA NA NA NA NA NA #> 5 NA NA NA NA NA NA NA #> 6 NA NA NA NA NA NA NA