R - Subset

> Procedural Languages > R

1 - About

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

Alternatively, you can use the subset operators

Advertising

3 - 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

4 - Random

# random subset of the original data of 15 rows
set.seed(1)
sample = data[sample(nrow(data), 15), ]
lang/r/subset.txt · Last modified: 2017/02/12 21:02 by gerardnico