drop_row: Filter Rows That Contain Markers

Description Usage Arguments Value Examples

View source: R/drop_row.R

Description

drop_row - Remove rows from a data set that contain a given marker/term.

keep_row - Keep rows from a data set that contain a given marker/term.

drop_empty_row - Removes the empty rows of a data set that are common in reading in data.

drop_NA - Removes the NA rows of a data set.

Usage

1
2
3
4
5
6
7
drop_row(dataframe, column, terms, ...)

keep_row(dataframe, column, terms, ...)

drop_empty_row(dataframe)

drop_NA(dataframe, column = TRUE, ...)

Arguments

dataframe

A dataframe object.

column

Column name to search for markers/terms.

terms

The regex terms/markers of the rows that are to be removed from the dataframe.

...

Other arguments passed to grepl.

Value

drop_row - returns a dataframe with the termed/markered rows removed.

drop_empty_row - returns a dataframe with empty rows removed.

drop_NA - returns a dataframe with NA rows removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
## drop_row EXAMPLE:
drop_row(DATA, "person", c("sam", "greg"))
keep_row(DATA, "person", c("sam", "greg"))
drop_row(DATA, 1, c("sam", "greg"))
drop_row(DATA, "state", c("Comp"))
drop_row(DATA, "state", c("I "))
drop_row(DATA, "state", c("you"), ignore.case=TRUE)

## drop_empty_row EXAMPLE:
(dat <- rbind.data.frame(DATA[, c(1, 4)], matrix(rep(" ", 4), 
   ncol =2, dimnames=list(12:13, colnames(DATA)[c(1, 4)]))))
drop_empty_row(dat)

## drop_NA EXAMPLE:
DATA[1:3, "state"] <- NA
drop_NA(DATA)

## End(Not run)

Example output

      person sex adult                         state code
1    teacher   m     1            What should we do?   K3
2      sally   f     0        How can we be certain?   K6
3      sally   f     0   What are you talking about?   K9
4 researcher   f     1 Shall we move on?  Good then.  K10
  person sex adult                                 state code
1    sam   m     0         Computer is fun. Not too fun.   K1
2   greg   m     0               No it's not, it's dumb.   K2
3    sam   m     0                  You liar, it stinks!   K4
4   greg   m     0               I am telling the truth!   K5
5   greg   m     0                      There is no way.   K7
6    sam   m     0                       I distrust you.   K8
7   greg   m     0 I'm hungry.  Let's eat.  You already?  K11
      person sex adult                         state code
1    teacher   m     1            What should we do?   K3
2      sally   f     0        How can we be certain?   K6
3      sally   f     0   What are you talking about?   K9
4 researcher   f     1 Shall we move on?  Good then.  K10
       person sex adult                                 state code
1        greg   m     0               No it's not, it's dumb.   K2
2     teacher   m     1                    What should we do?   K3
3         sam   m     0                  You liar, it stinks!   K4
4        greg   m     0               I am telling the truth!   K5
5       sally   f     0                How can we be certain?   K6
6        greg   m     0                      There is no way.   K7
7         sam   m     0                       I distrust you.   K8
8       sally   f     0           What are you talking about?   K9
9  researcher   f     1         Shall we move on?  Good then.  K10
10       greg   m     0 I'm hungry.  Let's eat.  You already?  K11
      person sex adult                                 state code
1        sam   m     0         Computer is fun. Not too fun.   K1
2       greg   m     0               No it's not, it's dumb.   K2
3    teacher   m     1                    What should we do?   K3
4        sam   m     0                  You liar, it stinks!   K4
5      sally   f     0                How can we be certain?   K6
6       greg   m     0                      There is no way.   K7
7      sally   f     0           What are you talking about?   K9
8 researcher   f     1         Shall we move on?  Good then.  K10
9       greg   m     0 I'm hungry.  Let's eat.  You already?  K11
      person sex adult                         state code
1        sam   m     0 Computer is fun. Not too fun.   K1
2       greg   m     0       No it's not, it's dumb.   K2
3    teacher   m     1            What should we do?   K3
4       greg   m     0       I am telling the truth!   K5
5      sally   f     0        How can we be certain?   K6
6       greg   m     0              There is no way.   K7
7 researcher   f     1 Shall we move on?  Good then.  K10
       person                                 state
1         sam         Computer is fun. Not too fun.
2        greg               No it's not, it's dumb.
3     teacher                    What should we do?
4         sam                  You liar, it stinks!
5        greg               I am telling the truth!
6       sally                How can we be certain?
7        greg                      There is no way.
8         sam                       I distrust you.
9       sally           What are you talking about?
10 researcher         Shall we move on?  Good then.
11       greg I'm hungry.  Let's eat.  You already?
12                                                 
13                                                 
       person                                 state
1         sam         Computer is fun. Not too fun.
2        greg               No it's not, it's dumb.
3     teacher                    What should we do?
4         sam                  You liar, it stinks!
5        greg               I am telling the truth!
6       sally                How can we be certain?
7        greg                      There is no way.
8         sam                       I distrust you.
9       sally           What are you talking about?
10 researcher         Shall we move on?  Good then.
11       greg I'm hungry.  Let's eat.  You already?
       person sex adult                                 state code
4         sam   m     0                  You liar, it stinks!   K4
5        greg   m     0               I am telling the truth!   K5
6       sally   f     0                How can we be certain?   K6
7        greg   m     0                      There is no way.   K7
8         sam   m     0                       I distrust you.   K8
9       sally   f     0           What are you talking about?   K9
10 researcher   f     1         Shall we move on?  Good then.  K10
11       greg   m     0 I'm hungry.  Let's eat.  You already?  K11

textclean documentation built on May 2, 2019, 7:22 a.m.