get_valid_rows: identify missing rows for model/formula.

Description Usage Arguments Details Value Examples

View source: R/linear.tools.R

Description

identify missing rows for model/formula.

Usage

1

Arguments

model

a formula or an output of lm or glm

data

the data.frame supposed to be used in modelling

Details

Data often contains missing values and lm() or glm() often skip those rows. This function is to identify which rows that lm() or glm() skips.

Value

a boolean vector with same length as the number of rows of data, with TRUE if a row has full data for the modelling and FALSE if not.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
model = lm(price ~ carat, head(ggplot2::diamonds,1000))
data = head(ggplot2::diamonds,10)

# so observation 1, 4, 7 will be not valid rows
data[c(1,4,7),"price"] = NA
data
get_valid_rows(model,data)

# error message as no "price" is found in the data
data[,"price"] = NULL
tryCatch(get_valid_rows(model,data),
         error = function(x){
           print(x)
         })

linear.tools documentation built on May 2, 2019, 3:17 a.m.