Learn R Programming

NMTox (version 0.1.0)

SubsetData: Create a subset of data

Description

This function creates a subset of dataset according to specified criteria.

Usage

SubsetData(data, x, x.cat, include = TRUE)

Value

This function returns a subset of data

Arguments

data

Data, structured in a dataframe

x

Variable(s) used to subset the data

x.cat

Specific criteria (value(s)) of x used to subset the data

include

Include/exclude value specified in x.cat. If include = TRUE (default value), then observations with x = x.cat are selected. If include = FALSE, then observations with value specified in x.cat will be omitted from the subset of the data.

Details

  • If there are several variable x used as criteria to subset the data, x.cat can be written as list(... , ...)

  • Values in x.cat should be specified in the same order as the x's

Examples

Run this code

# Create data of NM-400 (Multi-walled carbon nanotubes) from geninvitro dataset
data.sub<-SubsetData(data=geninvitro, x="name",
x.cat="NM-400 (Multi-walled carbon nanotubes)", include = TRUE)

# Create data of NM-400 (Multi-walled carbon nanotubes)
# with DNA STRAND BREAKS as the endpoint from geninvitro dataset
data.sub<-SubsetData(data=geninvitro, x=c("name","endpoint"),
x.cat=list("NM-400 (Multi-walled carbon nanotubes)","DNA STRAND BREAKS"),
include=TRUE)

# Exclude NM-400 (Multi-walled carbon nanotubes) from geninvitro dataset
data.sub<-SubsetData(data=geninvitro, x="name",
x.cat="NM-400 (Multi-walled carbon nanotubes)", include = FALSE)

# Create data of NM-400 (Multi-walled carbon nanotubes)
# and NM-110 (Zinc Oxide, uncoated) from geninvitro dataset
data.sub<-SubsetData(data=geninvitro, x="name",
x.cat=c("NM-400 (Multi-walled carbon nanotubes)",
"NM-110 (Zinc Oxide, uncoated)"), include = TRUE)

# Create data of NM-400 (Multi-walled carbon nanotubes)
# and NM-110 (Zinc Oxide, uncoated), with DNA STRAND BREAKS as the endpoint
data.sub<-SubsetData(data=geninvitro, x=c("name","endpoint"),
x.cat=list(c("NM-400 (Multi-walled carbon nanotubes)",
"NM-110 (Zinc Oxide, uncoated)"),"DNA STRAND BREAKS"),include = TRUE)

# Create a new dataset containing only control values from geninvitro dataset
controldata<-SubsetData(data=geninvitro, x="name", x.cat=c("control", "Control",
"medium", "medium + BSA", "untreated"))

Run the code above in your browser using DataLab