keep: Keep or lose variables and pick rows

Description Usage Arguments Details Author(s) See Also Examples

View source: R/keep.R

Description

keep or lose variables within dataframe

pick observations that satisfy specified condition

Usage

1
2
3
4
5
6
7

Arguments

data

dataframe (or Vector in pick)

...

variables

Details

keep

It keeps variables in the data, meaning that variables not specified are deleted. Variables can also be repositioned based on position.

lose

It works the same as keep, except that you specify the variables or observations to be lost from the dataframe.

Warning: drop and keep are not reversible. Once you have eliminated variables and assigned back, you cannot read them back in again. You would need to go back to the original dataframe and read it in again.

Instead of assigning back to the original dataframe, consider using multiple copies of dataframe subsets temporarily. This is usually the best strategy.

pick

It selects the rows that meets the specified conditions. This is the same as filter function in spreadsheet or subset in R.

Dataframe or vector can be used and epxressions to specify are almost similar.

arrange

It arranges the observations of the current data into ascending order based on the names of the variables. There is no limit to the number of variables that can be specified in the arguments. It can be in decreasing order if specified negative sign or "-" in front of the desired variable(s) without spacing.

Author(s)

Myo Minn Oo (Email: dr.myominnoo@gmail.com | Website: https://myominnoo.github.io/)

See Also

generate, recode, rename

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## Not run: 
keep(infert, education, age, parity)
keep(infert, parity, age:spontaneous, stratum) # variables repositioned

lose(infert, age, parity)
lose(infert, age:case, education)

pick(infert, age > 30)
pick(infert, parity == 6)
pick(infert, age > 30 & age < 35)
pick(infert, case == 0, age > 30 & age < 35, parity == 6)

# use vector instead of dataframe
age <- infert$age
pick(age, age > 40)
pick(infert, age > 40)

arrange(infert, age)
arrange(infert, -age)
arrange(infert, age, induced)
arrange(infert, age, -induced)
arrange(infert, age, -induced, case)
arrange(infert, age, -induced, -case)

arrange(infert, education)
arrange(infert, education, -age)

## End(Not run)

myominnoo/mStats_beta documentation built on Feb. 29, 2020, 8:17 a.m.