R - Subset

Card Puncher Data Processing

About

This function return subsets of vectors, matrices or data frames which meet conditions.

Alternatively, you can use the subset operators

Example

df = data.frame(numbers=1:5,Odd=c('Yes','No','Yes','No','Yes'))
odd = subset(df, df[,2]=='Yes')
odd
numbers Odd
1       1 Yes
3       3 Yes
5       5 Yes

Random

# random subset of the original data of 15 rows
set.seed(1)
sample = data[sample(nrow(data), 15), ]





Discover More
Card Puncher Data Processing
R - Data Manipulation

subset function, subset operators the package dplyr
Card Puncher Data Processing
R - Subset Operators (Extract or Replace Parts of an Object)

In the Data Manipulation category, you have the subset operators: [ [[ $ This operators acts on: vectors, matrices, arrays lists data.frame to extract or replace parts. See also:...



Share this page:
Follow us:
Task Runner