Learn R Programming

SciencesPo (version 1.02.12)

keep: Subset data

Description

Subsets a data.frame based on variables or/and records. It is a version of subset.data.frame which is a standard R function.

Usage

keep(data, select, subset, drop = FALSE, refactor = c("subset.vars", "all",
  "none"), sample = NULL, ...)

Arguments

data
= .data
select
the columns to select from data.
subset
the elements or rows to keep from data (missing values are taken as false).
drop
passed on to [ indexing operator.
refactor
whether the levels of variable(s) with zero count should be removed after subsetting. The default is refactor="subset.vars", which means that the levels of the variables not being used will be recycled.
sample
an integer for the size of random sample to retain from the data.
...
typically unecessary parameters.

encoding

UTF-8

Examples

Run this code
data(ssex)
info(ssex)
keep(ssex, select = c(Date, Oppose, Favor))

keep(ssex, subset=Oppose!="NA") # subset

Run the code above in your browser using DataLab